繁体   English   中英

角路由不会触发对templateUrl的获取请求

[英]angular routing would not trigger a get request to the templateUrl

我正在建立一个带有角度,节点,表达的Web应用程序。 当我使用角度路由时,它不会触发对templateUrl的GET请求。

angular.module('chat',['ngRoute']);
angular.module('chat')
  .config(['$routeProvider',function($routeProvider){
        $routeProvider.when('/users',{
            templateUrl:'/templates/users.html'
        })
    }]);

当我使用http://localhost/users URL时,它将发送回404错误。 但是我知道它不会触发对/templates/users.html的get请求,因为如果我提供完整的URL http://localhost/templates/users.html我会显示模板页面。 我应该如何设置它,以便在使用http://localhost/users URL时它将获取模板并在ng-view使用它。

您应该在templateUrl中使用relative-path。 如果您写路由的app.js应该参考.html模板,例如:如果您应用的文件结构是这样的:

-app.js , index.html
-templates/users.html

然后templateUrl:'templates/users.html'

要请求此路由,您应该请求localhost /#/ users,并使用“ controller”指定该路由的控制器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM