我在玩angular.js并尝试学习ng-bind和ng-bind-html。
首先,我的代码:
<div ng-app="module" ng-controller="controller as ctrl">
<div ng-bind-html="ctrl.html"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js"></script>
<script>
var themodule = angular.module("module", ["ngSanitize"]);
themodule.controller("controller", [function()
{
this.html = "<strong>Hello</strong><div>More</div>";
}
]);
</script>
即使有效,在控制台中也会出现以下错误:
Error: c.push is not a function
yc/this.$get</D.$$addBindingInfo<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:73:319
$d</<.compile/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:214:329
$@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:70:197
B@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:59:255
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:51:335
B@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:59:199
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:51:335
D/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:50:444
uc/d/</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:18:4
Pe/this.$get</n.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:126:11
Pe/this.$get</n.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:126:236
uc/d/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:477
e@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:36:313
uc/d@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:1
uc@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:18:179
Jd@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:1
@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:250:429
a@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:164:283
lf/c@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:32:384
<div class="ng-binding" ng-bind-html="ctrl.html">
我搜索了但是我找不到任何关于它的信息。
有谁知道为什么以及如何解决它?
谢谢!
答案 0 :(得分:1)
尝试使用此版本的angular-sanitize.js
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-sanitize.js"
OR
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.js"
并使用
var app = angular.module("myFirstApp", ['ngSanitize']);/*"angular-sanitize.js",
which has functions for removing potentially dangerous tokens from the HTML.*/
我希望你的问题能得到解决。