使用$ routeProvider

时间:2018-09-24 12:25:08

标签: angularjs

我正在学习AngularJS,并希望开发简单的示例。我想创建一个简单的路由。
这是temp.html文档:

<html>
<head>

    <script src="angular.min.js"></script>
    <script src="angular-route.js"></script>
    <script src="app.js"></script>
    <meta charset="utf8">
</head>
<body ng-app="routeApp">
    <a href="#/test">TEST</a>
    <ng-view></ng-view>
</body>

这是app.js:

var app=angular.module('routeApp' ,[])
.config(function($routeProvider){
    $routeProvider.when('/test' , {
        templateUrl : 'test.html'
    });
});

这是help.html

<html>
    <body>
        <h1>TEST PAGE</h1>
    </body>
</html>

我收到此错误

  

错误:[$ injector:modulerr] http://errors.angularjs.org/1.6.9/ $ injector / modulerr?p0 = routeApp&p1 = [$ injector:unpr] http://errors.angularjs.org/1.6.9/ $ injector / unpr?p0 =%24routeProvider   K / <@file:/// E:/YahyaApps/hello/angular.min.js:7:76   gb / p。$ injector <@file:/// E:/YahyaApps/hello/angular.min.js:46:64   d @ file:/// E:/YahyaApps/hello/angular.min.js:43:309   e @ file:/// E:/YahyaApps/hello/angular.min.js:44:39   invoke @ file:/// E:/YahyaApps/hello/angular.min.js:44:124   d @ file:/// E:/YahyaApps/hello/angular.min.js:42:271   g / <@file:/// E:/YahyaApps/hello/angular.min.js:42:418   r @ file:/// E:/YahyaApps/hello/angular.min.js:8:5   g @ file:/// E:/YahyaApps/hello/angular.min.js:42:180   gb @ file:/// E:/YahyaApps/hello/angular.min.js:46:250   c @ file:/// E:/YahyaApps/hello/angular.min.js:22:19   Uc @ file:/// E:/YahyaApps/hello/angular.min.js:22:332   we @ file:/// E:/YahyaApps/hello/angular.min.js:21:1   @file:/// E:/YahyaApps/hello/angular.min.js:336:241   b @ file:/// E:/YahyaApps/hello/angular.min.js:38:260

请帮助我!!!!

1 个答案:

答案 0 :(得分:0)

您需要添加ngRoute作为依赖项:

var app=angular.module('routeApp',['ngRoute']) //<---
.config(function($routeProvider){
    $routeProvider.when('/test' , {
        templateUrl : 'test.html'
    });
});