首页 > 解决方案 > Angularjs 注入器:modulerr 使用 $routeProvider 时

问题描述

我正在学习 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

请帮我!!!!

标签: angularjs

解决方案


您需要ngRoute添加为依赖项:

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

推荐阅读