【发布时间】:2017-02-11 11:15:44
【问题描述】:
在我有一个作为我的应用程序主体的主控制器之前,我有一个抽象父视图,它旨在与它的嵌套视图共享一个控制器
.state('main', {
abstract: true,
url: '/',
templateUrl: 'app/templates/main.html',
controller: 'mainController'
})
.state('main.edit', {
abstract: true,
url: '/edit',
templateUrl: 'app/templates/edit.html',
controller: 'editController'
})
.state('main.edit.details', {
url: '/details',
templateUrl: 'app/templates/editDetailsView.html',
controller: 'editDetailsController'
})
.state('main.edit.info', {
url: '/info',
templateUrl: 'app/templates/editInfoView.html',
controller: 'editInfoController'
})
路由按预期工作,在我设置 de 控制器之前,我有模块的父控制器,它将是编辑控制器和每个视图的每个控制器
错误:
"Error: [ng:areq] Argument 'editController' is not a function, got undefined
http://errors.angularjs.org/1.5.7/ng/areq?p0=editController&p1=not%20aNaNunction%2C%20got%20undefined
minErr/<@http://localhost:3000/js/libs.min.js:5:4923
assertArg@http://localhost:3000/js/libs.min.js:5:19120
assertArgFn@http://localhost:3000/js/libs.min.js:5:19322
$ControllerProvider/this.$get</<@http://localhost:3000/js/libs.min.js:7:31336
z/<.compile/<@http://localhost:3000/js/libs.min.js:15:2556
bind/<@http://localhost:3000/js/libs.min.js:5:12865
invokeLinkFn@http://localhost:3000/js/libs.min.js:7:22121
nodeLinkFn@http://localhost:3000/js/libs.min.js:7:4193
compositeLinkFn@http://localhost:3000/js/libs.min.js:6:26125
compile/<@http://localhost:3000/js/libs.min.js:6:24834
compilationGenerator/<@http://localhost:3000/js/libs.min.js:6:31172
l@http://localhost:3000/js/libs.min.js:15:1755
y/l.compile/<@http://localhost:3000/js/libs.min.js:15:2183
bind/<@http://localhost:3000/js/libs.min.js:5:12865
invokeLinkFn@http://localhost:3000/js/libs.min.js:7:22121
nodeLinkFn@http://localhost:3000/js/libs.min.js:7:4193
compositeLinkFn@http://localhost:3000/js/libs.min.js:6:26125
compile/<@http://localhost:3000/js/libs.min.js:6:24834
z/<.compile/<@http://localhost:3000/js/libs.min.js:15:2764
bind/<@http://localhost:3000/js/libs.min.js:5:12865
invokeLinkFn@http://localhost:3000/js/libs.min.js:7:22121
nodeLinkFn@http://localhost:3000/js/libs.min.js:7:4193
compositeLinkFn@http://localhost:3000/js/libs.min.js:6:26125
compile/<@http://localhost:3000/js/libs.min.js:6:24834
compilationGenerator/<@http://localhost:3000/js/libs.min.js:6:31172
l@http://localhost:3000/js/libs.min.js:15:1755
y/l.compile/</<@http://localhost:3000/js/libs.min.js:15:2175
$RootScopeProvider/this.$get</Scope.prototype.$broadcast@http://localhost:3000/js/libs.min.js:9:24515
v/y.transitionTo/y.transition<@http://localhost:3000/js/libs.min.js:14:29498
processQueue@http://localhost:3000/js/libs.min.js:9:8733
scheduleProcessQueue/<@http://localhost:3000/js/libs.min.js:9:9000
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:3000/js/libs.min.js:9:22223
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:3000/js/libs.min.js:9:19908
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:3000/js/libs.min.js:9:22650
done@http://localhost:3000/js/libs.min.js:8:7950
completeRequest@http://localhost:3000/js/libs.min.js:8:11757
createHttpBackend/</xhr.onload@http://localhost:3000/js/libs.min.js:8:12689
"
如果我删除了editController,它工作得很好,但是如果我需要我的视图的共享控制器,我该怎么办,如果我像这样设置父控制器,它可以工作
.state('main.edit', {
abstract: true,
url: '/edit',
templateUrl: 'app/templates/edit.html',
controller: function($scope){
console.log('edit parent controller');
}
不是这个想法。
【问题讨论】:
-
发布
editController的代码。 -
您似乎忘记指定控制器,或者控制器名称中有错字。
-
在每个控制器中我只有一个console.log,没有别的
-
angular.module('app.edit', []) .controller('editController', ['$scope', function($scope, $state) { console.log('edit' ); }]);
标签: angularjs angular-ui-router