错误是:
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) {
});
答案 0 :(得分:0)
您已将ui.router
注入主模块。尝试改为:
<强> app.js 强>
var myApp = angular.module( 'myApp', ['ui.router', 'ngResource', 'myApp.customer']);
<强> myApp.customer 强>
angular.module('myApp.customer', [])
需要注意的其他事项:
为什么在AppCtrl
之后您有function
:
myApp.controller( 'AppCtrl', function AppCtrl ( $scope, $location ) {