AngularJS ng-bind-html 指令详解及实例代码
网络编程 2021-07-04 20:00www.168986.cn编程入门
本文主要是对AngularJS ng-bind-html 指令知识的详细讲解,并附代码实例,有需要的小伙伴可以参考下
AngularJS ng-bind-html 指令
AngularJS 实例
绑定 <p> 内的 innerHTML 到变量 myText:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://apps.bdimg./libs/angular.js/1.4.6/angular.min.js"></script> <script src="http://apps.bdimg./libs/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>注意:</b> 该实例包含了 "angular-sanitize.js" 文件, 该文件移除 HTML 中的危险代码。</p> </body> </html>
运行结果:
my name is:
John Doe
注意:该实例包含了 "angular-sanitize.js" 文件, 该文件移除 HTML 中的危险代码。
定义和用法
ng-bind-html 指令是通一个安全的方式将内容绑定到 HTML 元素上。
当你想让 AngularJS 在你的应用中写入 HTML,你就需要去检测一些危险代码。通过在应用中引入 "angular-santize.js" 模块,使用 ngSanitize 函数来检测代码的安全性。 in your application you can do so by running the HTML code through the ngSanitize function.
语法
<element ng-bind-html="expression"></element>
所有的 HTML 元素都支持该指令。
参数值
值 | 描述 |
---|---|
expression | 指定要执行的变量或表达式。 |
以上就是AngularJS ng-bind-html 指令实例的详细介绍,有需要的朋友可以参考下。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程