angularjs - 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
请帮我!!!!
解决方案
您需要ngRoute
添加为依赖项:
var app=angular.module('routeApp',['ngRoute']) //<---
.config(function($routeProvider){
$routeProvider.when('/test' , {
templateUrl : 'test.html'
});
});
推荐阅读
- c++ - 为什么这个循环中需要分号?
- xml - 从 Oracle DB 根据 Key 从 CDATA 中提取值
- ruby-on-rails - 带参数的 Ransack 排序范围
- ruby-on-rails - 密码重置令牌泄露给谷歌分析
- asynchronous - 如何使用 Google Apps Script webapp 发送延迟响应(Slack api)?
- mathematical-optimization - minizinc 中条件变量
- python - 从两个元组列表(随机顺序)中取两个值并相乘
- javascript - 使用文字转语音消息发起呼叫
- pacemaker - 配置起搏器的src addr
- ssl - 智能手机浏览器上基于 SSL 的 socketIO