English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
binds the innerHTML within <p> to a variable myText:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></<script> <script src="https://cdn.staticfile.org/angular.js/1.5.0-beta.0/angular-sanitize.min.js"></script></head> <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> <p><b>Notice:</b>/b> This example includes "angular-"sanitize.js" file,</ This file removes dangerous code from HTML.</p> </body> </html>Test and see ‹/›
ng-bind-html Directives bind content to HTML elements in a secure way.
When you want AngularJS to write HTML in your application, you need to detect some dangerous code. By introducing "angular-Use the "sanitize.js" module to detect the safety of code with the ngSanitize function.
<element ng-bind-html="expression"></element>
All HTML elements support this directive.
Value | Description |
---|---|
expression | Specify the variable or expression to be executed. |