Ng-Bind-Html-3

 

In this example the variable $scope.myInputText has trusted html. The html contain a textbox and this variable is bind with the ng-bind-html directive so after the Your Name label a textbox shows which we bind with the directive. See the output.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular-sanitize.js"></script> </head> <body ng-app="myApp"> <div ng-controller="myController"> Your Name: <div ng-bind-html="myInputText"></div> </div> <script> var app = angular.module("myApp", ['ngSanitize']); app.controller('myController', ['$scope', '$sce', function ($scope, $sce) { $scope.myInputText = $sce.trustAsHtml("<input type='text' ng-model='name'/>"); }]); </script> </body> </html>
Output