简体   繁体   English

AngularJS routeProvider templateURL不起作用

[英]Angularjs routeProvider templateURL not working

I am trying to use ngRoute but I can't seem to get templateURL working. 我正在尝试使用ngRoute,但似乎无法使templateURL工作。 Everything works as expected except when I use templateURL. 一切正常,除了我使用templateURL时。

I have 4 different files: 我有4个不同的文件:

test.html test.html

<p>{{test}}</p>

test.js test.js

angular.module("app")
.controller("testController", ["$scope", function($scope) {
    $scope.test = 10;
}])

app.js app.js

angular.module("app", ["ngRoute"])
.config(function ($routeProvider) {
    $routeProvider.otherwise({"redirectTo": "1"})
        .when("/1", {
            "controller": "testController",
            "template": "{{test}}"
        })
        .when("/2", {
            "controller": "testController",
            "templateURL": "test.html"
        });
});

index.html index.html

<!DOCTYPE html>
<html>
    <body ng-app="app">
        <div ng-view=""></div>
        <script src="js/angular.js"></script>
        <script src="js/angular-route.js"></script>
        <script src="app.js"></script>
        <script src="test.js"></script>
    </body>
</html>

When I go to http://localhost:5000/#/1 , it shows 10 as expected. 当我转到http://localhost:5000/#/1 ,它显示了预期的10。 However, when I go to http://localhost:5000/#/2 , it doesn't show anything. 但是,当我转到http://localhost:5000/#/2 ,它什么也没有显示。

您在templateURL有一个错字,应该是templateUrl

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

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