EDIT
The reason you are having issues with getting $scope.name bound is because ng-bind-html does not bind that html to the current scope. You can use a directive to fix this. Here is an answer that fixes your issue.
Here is a plunker that adds the directive and shows the behavior you are looking for.
Here is the directive that was added that fixes your issue:
app.directive('compileTemplate', function($compile, $parse){ return { link: function(scope, element, attr){ var parsed = $parse(attr.ngBindHtml); function getStringValue() { return (parsed(scope) || '').toString(); } // Recompile if the template changes scope.$watch(getStringValue, function() { // The -9999 makes it skip directives // so that we do not recompile ourselves $compile(element, null, -9999)(scope); }); } } });
You need to declare $scope.name="Habib" before the myText scope variable.
var app = angular.module("myApp", ['ngSanitize']); app.controller("myCtrl", function($scope) { $scope.name="Habib"; $scope.myText = "My name is: <h1>{{name}}</h1>"; }); app.filter('unsafe', function ($sce) { return function(val) { return $sce.trustAsHtml(val); }; });