angular.js - Questions about angular routing
高洛峰
高洛峰 2017-05-15 16:52:23
0
1
596

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>
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
为情所困

I ran it according to your code and it works. I estimate that your error may appear in the following steps:

  • That homePage.html path can you see if it is correct
  • You can check the information that appears in your console, if it is the error message below XMLHttpRequest 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 chromePractice in the browser).
  • It seems to be able to run directly in the Firefox browser, and there seems to be no need to open a server.
  • Check carefully whether all the modules loaded by your code have been loaded, whether they are correct, and whether they are still thereindex.html页面中是否添加ng-app.

That’s basically it, you can take a closer look, I hope it can help you. ^_^

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template