AngularJS ng-bind-html instructions
AngularJS examples
InnerHTML bind <p> within the variable myText:
<Script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </ script>
<Script src = "http://apps.bdimg.com/libs/angular.js/1.5.0-beta.0/angular-sanitize.min.js"> </ script>
<Body>
<Div ng-app = "myApp " ng-controller = "myCtrl">
<P ng-bind-html = "myText"> </ p>
</ Div>
<Script>
var app = angular.module ( "myApp", [ 'ngSanitize']);
app.controller ( "myCtrl", function ($ scope) {
$ Scope.myText = "My name is: <h1> John Doe </ h1>";
});
</ Script>
<Script src = "http://apps.bdimg.com/libs/angular.js/1.5.0-beta.0/angular-sanitize.min.js"> </ script>
<Body>
<Div ng-app = "myApp " ng-controller = "myCtrl">
<P ng-bind-html = "myText"> </ p>
</ Div>
<Script>
var app = angular.module ( "myApp", [ 'ngSanitize']);
app.controller ( "myCtrl", function ($ scope) {
$ Scope.myText = "My name is: <h1> John Doe </ h1>";
});
</ Script>
try it"
Definition and Usage
ng-bind-html instruction is through a safe way to bind content to HTML elements.
AngularJS HTML when you want to write in your application, you need to detect dangerous code. By introducing the "angular-santize.js" module in the application, use ngSanitize function to detect security code. in your application you can do so by running the HTML code through the ngSanitize function.
grammar
<Element ng-bind-html = "expression"> </ element>
All HTML elements support the instruction.
Parameter Value
value | description |
---|---|
expression | Specifies that a variable or expression to be executed. |