Javascript Angular 1.4.5:未捕获的错误:[$injector:modulerr] ngRoute
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32572471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular 1.4.5 : Uncaught Error: [$injector:modulerr] ngRoute
提问by Nacim Idjakirene
When I try to refresh the page I have this error :
当我尝试刷新页面时出现此错误:
angular.js:38 http://errors.angularjs.org/1.4.5/$injector/modulerr?
p0=myApp&p1=Error%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.5%2Fangular.min.js%3A19%3A381)
angular.js:38 http://errors.angularjs.org/1.4.5/$injector/modulerr?
p0=myApp&p1=错误%3A%2…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.5%2Fangular.min.js%3A19%3A381)
I have a simple module with a dependency of ngRoute:
我有一个依赖 ngRoute 的简单模块:
var app = angular.module('myapp', ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl :'pages/main.html',
controller : 'mainController'
})
.when('/second',{
templateUrl : 'pages/second.html',
controller : 'secondController'
})
});
and my html code:
和我的 html 代码:
<html ng-app='myApp'>
<head><title>The title</title></head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5
/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js">
<script src="app.js"></script>
</script>
<body>
<div ng-view>
</div>
</body>
</html>
回答by Pankaj Parkar
Basically its typographical mistake.
基本上是它的印刷错误。
It should be
它应该是
<html ng-app='myapp'>
Instead of
代替
<html ng-app='myApp'>
Additionally correct your script tags like below.
另外更正您的脚本标签,如下所示。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js"></script>
<script src="app.js"></script>
回答by Sumanta Parida
var app = angular.module("myApp", ["ngRoute"]);
app.config(function( $routeProvider ) {
$routeProvider
.when("/home", {
template : "<h1>Main</h1><p>Click on the links to change this content</p>"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
templateUrl : "blue.htm"
});
});
回答by Blasanka
In my case I used $routeProvider.when({})
without url as first parameter and that was the case, when I add the url like below, error was gone.
在我的情况下,我$routeProvider.when({})
没有使用url 作为第一个参数,就是这样,当我添加如下所示的 url 时,错误消失了。
$routeProvider.when('/post/:id', {
templateUrl: 'views/post.html',
controller: 'PostController'
})