角度路由实现失败

时间:2017-04-25 10:45:59

标签: angularjs angular-ui-router

试图学习angluar路线构造,但我没有实施ngRoute

我的应用的定义

var app= angular.module('app', ['ngMaterial', 'ngRoute']);

配置

app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.otherwise({redirectTo: '/'});
}]);

我使用路由器的指令

app.directive("applicationDirective", function($router) {

    return {
        restrict : "E",
        templateUrl: 'app/templates/application.html',
        controller: 'applicationController'
    };

});

我的HTML实现

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">

        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-animate.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-aria.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-messages.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.js"></script>

        <script src="app/app.js"></script>

似乎没事;但失败......随着:

angular.js:14525 Error: [$injector:unpr] Unknown provider: $routerProvider <- $router <- applicationDirectiveDirective
http://errors.angularjs.org/1.6.4/$injector/unpr?p0=%24routerProvider%20%3C-%20%24router%20%3C-%20applicationDirectiveDirective
    at angular.js:66
    at angular.js:4789
    at Object.getService [as get] (angular.js:4944)
    at angular.js:4794
    at getService (angular.js:4944)
    at injectionArgs (angular.js:4969)
    at Object.invoke (angular.js:4995)
    at angular.js:8110
    at forEach (angular.js:403)
    at Object.<anonymous> (angular.js:8108)

是否有人提示如何解决它。

问候 n00n

1 个答案:

答案 0 :(得分:1)

您需要在配置功能中设置路由。不需要此指令,它不会像这样工作。 看一下这个: https://www.w3schools.com/angular/angular_routing.asp