search

Home  >  Q&A  >  body text

angular.js - Questions about angular routing

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>
高洛峰高洛峰2826 days ago598

reply all(1)I'll reply

  • 为情所困

    为情所困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:

    • 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. ^_^

    reply
    0
  • Cancelreply