如何删除给定的错误“由于以下原因无法实例化模块应用程序:”
how to remove given error " 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
的方法。这就是导致错误消息的原因。
我正在尝试在 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
的方法。这就是导致错误消息的原因。