[英]Angular Partials: templateUrl Routing Local .HTML File
I've had this problem for over 2 days and I've spent around 10 hours researching, but NOTHING has worked so far. 我已经有超过2天的时间遇到了这个问题,并且花了大约10个小时进行研究,但是到目前为止,“一切”都没有起作用。 I'm keeping my stress levels in check, but this is downright infuriating!
我一直在控制压力水平,但这实在令人发指!
This jsfiddle has everything aside from the "page1.html" file that I'm trying to load 除了我尝试加载的“ page1.html”文件之外,此jsfiddle拥有所有内容
http://jsfiddle.net/tAmr3/ http://jsfiddle.net/tAmr3/
I want to load a sibling (same directory), page1.html file as such: 我想像这样加载同级(相同目录)的page1.html文件:
var playground = angular.module("playground",['ngRoute'])
.config(function($routeProvider){
$routeProvider.when('/Page1', {
templateUrl: 'page1.html', // **THIS LINE DOES NOT WORK**
controller:'page1Ctrl'
}).otherwise({redirectTo:'/'})
});
The problem is that "templateUrl" refuses to work!!! 问题是“ templateUrl”拒绝工作!!!
The $routeProvider
knows when I'm trying to access Page1
because page1Ctrl
is console.logging successfully $routeProvider
知道我何时尝试访问Page1
因为page1Ctrl
是console.logging成功
The problem here was serving the angular app over file://
and having Angular trigger a cross-origin request when it tried to fetch the template over http://
. 这里的问题是通过
file://
服务有角度的应用程序,当Angular尝试通过http://
获取模板时触发了跨域请求。
The easiest solution to that is to use a webserver rather than accessing the file-system directly. 最简单的解决方案是使用Web服务器,而不是直接访问文件系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.