I want to use routeProvider and template in angular to switch the view of the content part. Why can’t it be achieved by writing this way? The code is as follows.
PS background is not NODE
index.html
...
<p id="content-holder">
<p ng-view></p>
</p>
...
route.js:
var myApp = angular.module('myApp',['ngRoute']);
myApp.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/',{
templateUrl:"page/home/homePage.html",
controller:"contentController"
})
.otherwise({
redirectTo: '/'
});
}]);
myApp.controller("contentController",function(){
...
});
homePage.html:
<p id="content" data-role="content">
...
</p>
为情所困2017-05-15 16:54:23
I ran it according to your code and it works. I estimate that your error may appear in the following steps:
homePage.html
path can you see if it is correctXMLHttpRequest cannot load file:///******/test/1/page/home/homePage.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
说明你的整个文件夹不是在一个服务器下运行,因为要加载外部的html代码,所以浏览器是禁止的,只有通过本地的一个服务器才可以运行(这个是在google chrome
Practice in the browser). index.html
页面中是否添加ng-app
. That’s basically it, you can take a closer look, I hope it can help you. ^_^