''访问受限URI被拒绝'"尝试使用ng模板时出错
''Access to restricted URI denied'" error when trying to use ng-template
我正在尝试使用ng-include作为html中的递归模板。我第一次用jsfiddle尝试它,它很有效。这是URLhttp://jsfiddle.net/uXbn6/3115/。然而,当我尝试在本地做同样的事情时。我得到这个错误:
Error: Access to restricted URI denied
createHttpBackend/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:10765:1
sendReq@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:10558:1
$http/serverRequest@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:10268:16
processQueue@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:14792:28
scheduleProcessQueue/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:14808:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:16052:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:15870:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:16160:13
bootstrapApply@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:1679:9
invoke@http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js:4523:14
这是我完整的源代码文件:
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
<script>
angular.module("Application", []).
controller("TreeController", ['$scope', function($scope) {
$scope.links = [{
"id": 1,
"fc": "FC_1",
"adjacentLists": [{
"id": 2,
"fc": "FC_1",
"adjacentLists": [{
"id": 3,
"fc": "FC_1",
"adjacentLists": [{
"id": 7,
"fc": "FC_1",
"speedLimit": 55
}, {
"id": 6,
"fc": "FC_1",
"speedLimit": 60
}, {
"id": 8,
"fc": "FC_1",
"speedLimit": 0
}],
"speedLimit": 0
}, {
"id": 4,
"fc": "FC_1",
"speedLimit": 0
}, {
"id": 5,
"fc": "FC_2",
"adjacentLists": [{
"id": 9,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 9 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}, {
"id": 11,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 11 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0,
"query": {
"question": "Link 5 has differnet function class of FC_2 instead of FC_1 of source link 2. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0
}],
"speedLimit": 50
}, {
"id": 2,
"fc": "FC_1",
"adjacentLists": [{
"id": 3,
"fc": "FC_1",
"adjacentLists": [{
"id": 7,
"fc": "FC_1",
"speedLimit": 55
}, {
"id": 6,
"fc": "FC_1",
"speedLimit": 60
}, {
"id": 8,
"fc": "FC_1",
"speedLimit": 0
}],
"speedLimit": 0
}, {
"id": 4,
"fc": "FC_1",
"speedLimit": 0
}, {
"id": 5,
"fc": "FC_2",
"adjacentLists": [{
"id": 9,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 9 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}, {
"id": 11,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 11 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0,
"query": {
"question": "Link 5 has differnet function class of FC_2 instead of FC_1 of source link 2. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0
}, {
"id": 3,
"fc": "FC_1",
"adjacentLists": [{
"id": 7,
"fc": "FC_1",
"speedLimit": 55
}, {
"id": 6,
"fc": "FC_1",
"speedLimit": 60
}, {
"id": 8,
"fc": "FC_1",
"speedLimit": 0
}],
"speedLimit": 0
}, {
"id": 4,
"fc": "FC_1",
"speedLimit": 0
}, {
"id": 5,
"fc": "FC_2",
"adjacentLists": [{
"id": 9,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 9 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}, {
"id": 11,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 11 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0,
"query": {
"question": "Link 5 has differnet function class of FC_2 instead of FC_1 of source link 2. Do you want to continue?",
"response": false
}
}, {
"id": 6,
"fc": "FC_1",
"speedLimit": 60
}, {
"id": 7,
"fc": "FC_1",
"speedLimit": 55
}, {
"id": 8,
"fc": "FC_1",
"speedLimit": 0
}, {
"id": 10,
"fc": "FC_1",
"adjacentLists": [{
"id": 9,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 9 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}, {
"id": 11,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 11 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}],
"speedLimit": 0
}, {
"id": 9,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 9 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}, {
"id": 11,
"fc": "FC_3",
"speedLimit": 0,
"query": {
"question": "Link 11 has differnet function class of FC_3 instead of FC_2 of source link 5. Do you want to continue?",
"response": false
}
}];
$scope.link = $scope.links[0];
}]);
</script>
<script type="text/ng-template" id="tree_item_renderer.html">
Processing Link {{link.id}}</br>
<span ng-if="link.query">
{{link.query.question}}
</span>
<span ng-if="link.adjacentLists.length>0">
<ul>
<li ng-repeat="link in link.adjacentLists" ng-include="'tree_item_renderer.html'"></li>
</ul>
</span>
</script>
<body>
<ul ng-app="Application" ng-controller="TreeController">
<span ng-include="'tree_item_renderer.html'"></span>
</ul>
</body>
</html>
您的问题是,您可能正在打开file://
协议上的html文件。尝试使用一个简单的http服务器在本地提供它(例如,如果您安装了Python,文件所在目录中的python -m SimpleHTTPServer
)。
根据ngInclude
:的Angular文档
默认情况下,模板URL被限制为与应用程序文档相同的域和协议。这是通过调用它上的$se.getTrustedResourceUrl来完成的。要从其他域或协议加载模板,您可以将它们列入白名单,也可以将它们包装为可信值。请参阅Angular的严格上下文转义。
此外,浏览器的同源策略和跨源资源共享(CORS)策略可能会进一步限制模板是否成功加载例如,ngInclude不适用于所有浏览器上的跨域请求,也不适用于某些浏览器上的file://access[强调矿]
附言:运行从本地服务器提供的代码是有效的。:)
相关文章:
- ng映射方向备选方案
- AngularJS UI路由器不能像ng路由器那样工作
- 角度:在ng重复上切换图像
- javascript中的数组出错
- 正在使用$location.path(.)路由ng视图
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- AngularJS:ng之后,重复$scope值未按预期更新
- ng打开空字符串
- ng路由injectore:modulerr中出错[$injector:modulerr]http://errors.a
- angularjs[ng:areq]参数'fn'不是函数,在控制台中获取字符串时出错
- 使用 ng-repeat呈现嵌套指令时出错
- 在ng重复中注入图像源时出错
- 根据依赖关系加载不同的模板解决使用 ng-route 时出错
- 尝试角度ng路由时出错
- 在ui视图内部使用ng-include时出错
- ''访问受限URI被拒绝'"尝试使用ng模板时出错
- 使用angular.js进行ng重复时出错
- 在Angular 2项目中运行ng serve -aot命令出错
- AngularJS: $rootScope:infdig在ng-repeat中调用ng风格的函数时出错
- AngularJs:编译ng开关时出错