由于无法实例化依赖性模块,无法实例化模块

时间:2016-02-25 01:35:55

标签: angularjs

错误是:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module myApp.customer due to:
Error: [$injector:nomod] Module 'myApp.customer' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我的app.js包含以下代码:

var myApp = angular.module( 'myApp', ['ui.router',
'myApp.customer'    

]);

myApp.config( function myAppConfig ( $stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise( '/account' );
});

myApp.run( function run () {
});


myApp.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams,    fromState, fromParams){
if ( angular.isDefined( toState.data.pageTitle ) ) {
  $scope.pageTitle = toState.data.pageTitle ;
}
});
});

myApp.customer模块如下:

angular.module('myApp.customer', ['ui.router','ngResource'])
.config(function($stateProvider) {
$stateProvider.state('customer', {
        url:'/customer',
        views: {
            'main': {
                templateUrl:'customer/customer.tpl.html',
                controller: 'CustomerCtrl'
            }
        },
        resolve: {

        },
        data : { pageTitle : "Customers" }
  });
 })


.controller("CustomerCtrl", function($scope) {
});

1 个答案:

答案 0 :(得分:0)

您已将ui.router注入主模块。尝试改为:

<强> app.js

var myApp = angular.module( 'myApp', ['ui.router', 'ngResource', 'myApp.customer']);

<强> myApp.customer

angular.module('myApp.customer', [])

需要注意的其他事项:

  1. 你的脚本是否正确?
  2. 为什么在AppCtrl之后您有function

    myApp.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {