注入'ui.router'时出错模块

时间:2021-10-29 19:40:33

When I use the ui.router, I got the error message "Error Module" and it failed to instantiate module xPlat. In html file I use the angular-ui-router verson 0.2.11

当我使用ui.router时,我收到错误消息“Error Module”,它无法实例化模块xPlat。在html文件中,我使用angular-ui-router verson 0.2.11

below is my injection of ui.route :

下面是我注入的ui.route:

(function () {
    'use strict';
    angular.module('xPlat', ['ui.router'])
    .config(function ($stateProvider) {
        $stateProvider
            .state('views', {
                url: '/views',
                templateUrl: 'views/item.html'
            })
            .state('views.posItem', {
                url: '/views',
                templateUrl: 'views/posItem.html'
            })
            .otherwise('/views');
    })
})();

I don't understand about it, why it error?

我不明白,为什么会出错?

this is error that I got :

这是我得到的错误:

Error: error:modulerr Module Error

错误:错误:modulerr模块错误

Failed to instantiate module xPlat due to:
TypeError: undefined is not a function
    at http://localhost:4400/scripts/app.js:14:14
    at Object.d [as invoke] (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:30:210)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:29:58
    at Array.forEach (native)
    at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:7:261)
    at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:28:374)
    at Xb (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:32:427)
    at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:17:315)
    at Wb (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:18:30)
    at Oc (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:17:99

And description of error:

并描述错误:

This error occurs when a module fails to load due to some exception. The error message above should provide additional context.

由于某些异常导致模块加载失败时会发生此错误。上面的错误消息应提供其他上下文。

4 个解决方案

#1


2  

.otherwise('/views'); is for the $urlRouterProvider not the $stateProvider

不然的话( '/视图');是$ urlRouterProvider而不是$ stateProvider

(function () {
'use strict';
angular.module('xPlat', ['ui.router'])
.config(function ($urlRouterProvider, $stateProvider) {
    $urlRouterProvider.otherwise('/views');
    $stateProvider
        .state('views', {
            url: '/views',
            templateUrl: 'views/item.html'
        })
        .state('views.posItem', {
            url: '/views',
            templateUrl: 'views/posItem.html'
        })            
})
})();

#2


0  

You have to inject $stateProvider

你必须注入$ stateProvider

(function () {
    'use strict';
    angular.module('xPlat', ['ui.router'])
    .config(['$stateProvider', function ($stateProvider) {
        $stateProvider
            .state('views', {
                url: '/views',
                templateUrl: 'views/item.html'
            })
            .state('views.posItem', {
                url: '/views',
                templateUrl: 'views/posItem.html'
            })
            .otherwise('/views');
    }])
})();

#3


0  

I was getting same error until I changed the reference in my index.html from angular-ui-router.min.js to angular-ui-router.js

在我将index.html中的引用从angular-ui-router.min.js更改为angular-ui-router.js之前,我遇到了同样的错误

I know it may not be desired solution, but for me the minified library was just not working.

我知道它可能不是理想的解决方案,但对我来说,缩小的库只是不起作用。

If you work with npm, your reference should look sth like this:

如果您使用npm,您的引用应该看起来像这样:

<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>

#4


0  

The way you load UI Router has changed. According to the docs (https://docs.angularjs.org/api/ngRoute), it needs to be done like this:

加载UI路由器的方式已更改。根据文档(https://docs.angularjs.org/api/ngRoute),它需要像这样完成:

angular.module('app', ['ngRoute']);

This solved the problem for me.

这解决了我的问题。

#1


2  

.otherwise('/views'); is for the $urlRouterProvider not the $stateProvider

不然的话( '/视图');是$ urlRouterProvider而不是$ stateProvider

(function () {
'use strict';
angular.module('xPlat', ['ui.router'])
.config(function ($urlRouterProvider, $stateProvider) {
    $urlRouterProvider.otherwise('/views');
    $stateProvider
        .state('views', {
            url: '/views',
            templateUrl: 'views/item.html'
        })
        .state('views.posItem', {
            url: '/views',
            templateUrl: 'views/posItem.html'
        })            
})
})();

#2


0  

You have to inject $stateProvider

你必须注入$ stateProvider

(function () {
    'use strict';
    angular.module('xPlat', ['ui.router'])
    .config(['$stateProvider', function ($stateProvider) {
        $stateProvider
            .state('views', {
                url: '/views',
                templateUrl: 'views/item.html'
            })
            .state('views.posItem', {
                url: '/views',
                templateUrl: 'views/posItem.html'
            })
            .otherwise('/views');
    }])
})();

#3


0  

I was getting same error until I changed the reference in my index.html from angular-ui-router.min.js to angular-ui-router.js

在我将index.html中的引用从angular-ui-router.min.js更改为angular-ui-router.js之前,我遇到了同样的错误

I know it may not be desired solution, but for me the minified library was just not working.

我知道它可能不是理想的解决方案,但对我来说,缩小的库只是不起作用。

If you work with npm, your reference should look sth like this:

如果您使用npm,您的引用应该看起来像这样:

<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>

#4


0  

The way you load UI Router has changed. According to the docs (https://docs.angularjs.org/api/ngRoute), it needs to be done like this:

加载UI路由器的方式已更改。根据文档(https://docs.angularjs.org/api/ngRoute),它需要像这样完成:

angular.module('app', ['ngRoute']);

This solved the problem for me.

这解决了我的问题。