简体   繁体   English

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

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

i'm building a web app with angular, node, express. 我正在建立一个带有角度,节点,表达的Web应用程序。 when i use angular-routing it wont trigger a GET request to the templateUrl . 当我使用角度路由时,它不会触发对templateUrl的GET请求。

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

when i use the http://localhost/users URL it sends back a 404 err. 当我使用http://localhost/users URL时,它将发送回404错误。 but i know it isn't firing the get request to /templates/users.html because if i provide the full URL http://localhost/templates/users.html i get the template page displayed. 但是我知道它不会触发对/templates/users.html的get请求,因为如果我提供完整的URL http://localhost/templates/users.html我会显示模板页面。 How should i set it up to work that when i use http://localhost/users URL it will fetch the template and use it in ng-view . 我应该如何设置它,以便在使用http://localhost/users URL时它将获取模板并在ng-view使用它。

You should use relative-path in templateUrl. 您应该在templateUrl中使用relative-path。 If your app.js where the routes are written should refer to the .html template relatively like : if your app's file structure like this : 如果您写路由的app.js应该参考.html模板,例如:如果您应用的文件结构是这样的:

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

then templateUrl:'templates/users.html' 然后templateUrl:'templates/users.html'

To request this route you should request localhost/#/users , also specify the controller for this route using the 'controller' 要请求此路由,您应该请求localhost /#/ users,并使用“ controller”指定该路由的控制器

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

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