如何删除给定的错误" Failed to instantiate module app due to:"



我正在尝试用angular js制作简单的应用程序。我的项目中包括js文件。但是我收到这个错误

**Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module app.stationselect due to:
TypeError: $urlRouterProvider.state is not a function
at routeChange (http://localhost:63342/www/js/stationselect/router.js:9:28)
at Object.invoke (http://localhost:63342/www/lib/ionic.bundle.js:12877:17)
at runInvokeQueue (http://localhost:63342/www/lib/ionic.bundle.js:12783:35)
at http://localhost:63342/www/lib/ionic.bundle.js:12792:11
at forEach (http://localhost:63342/www/lib/ionic.bundle.js:9015:20)
at loadModules (http://localhost:63342/www/lib/ionic.bundle.js:12773:5)
at http://localhost:63342/www/lib/ionic.bundle.js:12790:40
at forEach (http://localhost:63342/www/lib/ionic.bundle.js:9015:20)
at loadModules (http://localhost:63342/www/lib/ionic.bundle.js:12773:5)
at createInjector (http://localhost:63342/www/lib/ionic.bundle.js:12699:11)
http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=app.stationselect&…(http%3A%2F%2Flocalhost%3A63342%2Fwww%2Flib%2Fionic.bundle.js%3A12699%3A11)
at REGEX_STRING_REGEXP (http://localhost:63342/www/lib/ionic.bundle.js:8755:12)
at http://localhost:63342/www/lib/ionic.bundle.js:12812:15
at forEach (http://localhost:63342/www/lib/ionic.bundle.js:9015:20)
at loadModules (http://localhost:63342/www/lib/ionic.bundle.js:12773:5)
at http://localhost:63342/www/lib/ionic.bundle.js:12790:40
at forEach (http://localhost:63342/www/lib/ionic.bundle.js:9015:20)
at loadModules (http://localhost:63342/www/lib/ionic.bundle.js:12773:5)
at createInjector (http://localhost:63342/www/lib/ionic.bundle.js:12699:11)
at doBootstrap (http://localhost:63342/www/lib/ionic.bundle.js:10137:20)
at bootstrap (http://localhost:63342/www/lib/ionic.bundle.js:10158:12)
http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=app&p1=Error%3A%20…(http%3A%2F%2Flocalhost%3A63342%2Fwww%2Flib%2Fionic.bundle.js%3A10158%3A12)**

实际上我检查

当我从index.html中删除一个脚本时,它会删除那个错误脚本就是这个

<script src="js/stationselect/router.js"></script>

但当我再次包含时,它再次显示给定的错误

我不知道我写错了什么?事实上,在我的应用程序中有一些目录,所以我不能使用fiddle。我会和你分享我的代码

https://dl.dropbox.com/s/l2dtrxmnsurccxt/www.zip?dl=0

这是我的脚本代码

(function(){
'use strict'
angular.module('app.stationselect').config(routeChange);
routeChange.$inject=['$stateProvider','$urlRouterProvider'];
function routeChange($stateProvider, $urlRouterProvider){
$urlRouterProvider.state('selectstation',{
url:'/selectstation',
controller:'selectStation',
templateUrl:'js/stationselect/partial/home.html'
})
$urlRouterProvider.otherwise('/selectstation');
}
})();

看起来你应该有

angular.module('app.stationselect', ['ui.router']).config(...)

如果您在那里创建app.stationselect模块。

当您只向angular.module()提供一个参数(即模块名称)时,Angular会尝试从模块注册表中检索它。

如果您已经在其他地方创建了模块,请忽略上面的内容。

此外,.state$stateProvider的一种方法,而不是$urlRouterProvider。这就是导致错误消息的原因。

相关内容

最新更新