Ng-Bind-Html-2

 

In this example $scope.myInputText variable has trusted html with the text "My name is John Steve" and the name "John Steve" is in bold tag. The variable $scope.myInputText is bind with the ng-bind-html directive and shows the name as bold. 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"> <span ng-bind-html="myInputText"></span> </div> <script> var app = angular.module("myApp", ['ngSanitize']); app.controller('myController', ['$scope','$sce', function ($scope,$sce) { $scope.myInputText = $sce.trustAsHtml("My name is <span><b>John Steve</b></span>"); }]); </script> </body> </html>
Output