国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

angularjs中使用ng-bind-html和ng-include的實(shí)例

2019-11-19 16:42:23
字體:
供稿:網(wǎng)友

下面這個(gè)例子,往div標(biāo)簽內(nèi)添加html內(nèi)容:

<!doctype html><html ng-app="myApp"><head> <meta charset="UTF-8"> <title>demo</title> <script type="text/javascript" src="lib/angularjs/angular.min.js" charset="utf-8"></script> </head><body ng-controller="ctrl">  <div ng-bind-html="myText"></div><script>var app = angular.module('myApp',[]);app.controller("ctrl",function($scope,$sce){  $scope.myText = $sce.trustAsHtml("<b>粗體內(nèi)容</b><br/><i>斜體內(nèi)容</i>");});</script></body></html>

注意在賦值時(shí)需要將html用$sce.trustAsHtml作一個(gè)處理,不然頁面會(huì)報(bào)錯(cuò),無法輸出內(nèi)容。

下面是ng-include的使用示例,跟上面的例子差不多,只是把要添加的html內(nèi)容放到一個(gè)文件中:

<!doctype html><html ng-app="myApp"><head> <meta charset="UTF-8"> <title>demo</title> <script type="text/javascript" src="lib/angularjs/angular.min.js" charset="utf-8"></script> </head><body ng-controller="ctrl">  <div ng-include="'demo1_1.html'"></div><script>var app = angular.module('myApp',[]);app.controller("ctrl",function($scope){});</script></body></html>

demo1_1.html

<b>粗體內(nèi)容222</b><br/><i>斜體內(nèi)容222</i>

以上這篇angularjs中使用ng-bind-html和ng-include的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 岳阳县| 英德市| 塔城市| 大荔县| 霍州市| 永丰县| 丰城市| 容城县| 仁怀市| 盐城市| 武邑县| 吴堡县| 丰城市| 万源市| 阳东县| 盈江县| 临泉县| 仁寿县| 原平市| 唐河县| 台江县| 公主岭市| 永善县| 清苑县| 洪洞县| 达尔| 开鲁县| 镇坪县| 崇阳县| 中牟县| 嘉善县| 汶上县| 老河口市| 明光市| 盐山县| 从江县| 石景山区| 甘洛县| 桃园县| 龙口市| 隆德县|