Angularjs ocLazyLoad:使用ngSanitizer时出错
我想使用angular应用程序ngSanitize在我的应用程序中使用纯HTML。我基本上希望重现所解释的功能,但我想用ocLazyLoad延迟加载模块。但由于某些原因,我仍然收到错误Angularjs ocLazyLoad:使用ngSanitizer时出错,angularjs,lazy-loading,Angularjs,Lazy Loading,我想使用angular应用程序ngSanitize在我的应用程序中使用纯HTML。我基本上希望重现所解释的功能,但我想用ocLazyLoad延迟加载模块。但由于某些原因,我仍然收到错误错误:[$sce:unsafe]试图在安全上下文中使用不安全值,表明ngSanitize未正确加载 是我做错了什么还是这是一个错误 这里是一个缩小的示例: <!DOCTYPE html> <html> <head> <title></title>
错误:[$sce:unsafe]试图在安全上下文中使用不安全值
,表明ngSanitize未正确加载
是我做错了什么还是这是一个错误
这里是一个缩小的示例:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.11.2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular.js"></script>
<script src="ocLazyLoad.js"></script>
</head>
<body>
<div id="example" ng-app="LazyLoadTest" ng-controller="TestController">
<p ng-bind-html="myHTML"></p>
</div>
<script>
angular.module("LazyLoadTest", [ "oc.lazyLoad"])
.controller("TestController", function($scope, $ocLazyLoad, $compile){
$ocLazyLoad.load({
name: "ngSanitize",
files: ["angular-sanitize.js"],
serie: true
}).then(function () {
$scope.myHTML =
'I am an <code>HTML</code>string with ' +
'<a href="#">links!</a> and other <em>stuff</em>';
}, function (e) {
console.log(e);
})
});
</script>
</body>
</html>
此处不使用延迟加载:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.11.2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.7/angular.js"></script>
<script src="angular-sanitize.js"></script>
</head>
<body>
<div id="example" ng-app="LazyLoadTest" ng-controller="TestController">
<p ng-bind-html="myHTML"></p>
</div>
<script>
angular.module("LazyLoadTest", [ "ngSanitize"])
.controller("TestController", function($scope){
$scope.myHTML =
'I am an <code>HTML</code>string with ' +
'<a href="#">links!</a> and other <em>stuff</em>';
});
</script>
</body>
</html>
看
显然,NGSanitarizer与AngularJS的耦合过于紧密,无法延迟加载
编辑:
请注意,这一事实现在也在本文中提到