2015-09-05 107 views
0

我已阅读了其他相关主题并尝试了他们推荐的解决方案,但我无法弄清楚。据我所知,ngRoute通过标签正确地链接到项目,然后作为依赖注入。我已经尝试了很多不同的东西(比如使用ui-router)而没有任何东西可以工作。任何帮助将非常感激!

完整的错误读取:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: 
Error: [$injector:unpr] Unknown provider: $stateProvider 
http://errors.angularjs.org/1.4.5/$injector/unpr?p0=%24stateProvider 
    at REGEX_STRING_REGEXP (http://localhost:8000/static/bower_components/angular/angular.js:68:12) 
    at http://localhost:8000/static/bower_components/angular/angular.js:4284:19 
    at getService (http://localhost:8000/static/bower_components/angular/angular.js:4432:39) 
    at Object.invoke (http://localhost:8000/static/bower_components/angular/angular.js:4464:13) 
    at runInvokeQueue (http://localhost:8000/static/bower_components/angular/angular.js:4379:35) 
    at http://localhost:8000/static/bower_components/angular/angular.js:4388:11 
    at forEach (http://localhost:8000/static/bower_components/angular/angular.js:336:20) 
    at loadModules (http://localhost:8000/static/bower_components/angular/angular.js:4369:5) 
    at createInjector (http://localhost:8000/static/bower_components/angular/angular.js:4294:11) 
    at doBootstrap (http://localhost:8000/static/bower_components/angular/angular.js:1655:20) 
http://errors.angularjs.org/1.4.5/$injector/modulerr?p0=myApp&p1=Error%3A%2…host%3A8000%2Fstatic%2Fbower_components%2Fangular%2Fangular.js%3A1655%3A20) 

的index.html:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Test</title> 
</head> 
<body ng-app="myApp"> 

    <div ng-controller="MainCtrl"> 
     {{ test }} 
    </div> 

    <script src="static/bower_components/angular/angular.js"></script> 
    <script src="static/bower_components/angular-route/angular-route.min.js"></script> 
    <script src="static/components/app.js"></script> 
</body> 
</html> 

app.js:

'use strict'; 

function() { 
    angular.module('myApp', ['ngRoute']) 
     .controller('MainCtrl', function ($scope) { 
      $scope.test = 'hello world'; 
     }); 
})(); 

回答

0

我认为ngRoute(角route.js)的用途提供者$ routeProvider和ui-router(angular-ui-router.js)使用提供者$ stateProvider。

看看这个答案。 What is the difference between angular-route and angular-ui-router?

如果是这样的话。 解决方法1.改变脚本角route.js到角-UI-router.js 解决方案2.更换提供商$ routeProvider

希望它可以帮助

1

这不是一个路径问题。你的app.js中缺少括号,你的代码应该是这样的。

'use strict'; 

(function() { 
    angular.module('myApp', ['ngRoute']) 
     .controller('MainCtrl', function ($scope) { 
      $scope.test = 'hello world'; 
     }); 
})(); 
0

如果以上所有答案都失败了,请试试这一个。

我认为这个问题是与包括脚本...

解决方案1:angular.min.js以及角route.min.js复制到当前文件夹,并把它作为

<script src="angular.min.js"></script>

如果它不工作,

解决方案2: 尝试增加上面的脚本,在标题标签结束后的头标上。

相关问题