Angularjs错误:错误:[$compile:ctreq]控制器';testParent';,指令'要求;testChildren';,can';找不到
环境优先:angularjs 1.2 rc1 我需要两个指令:parent和children,因此我使用require:true,但我遇到了一个问题:Angularjs错误:错误:[$compile:ctreq]控制器';testParent';,指令'要求;testChildren';,can';找不到,angularjs,directive,Angularjs,Directive,环境优先:angularjs 1.2 rc1 我需要两个指令:parent和children,因此我使用require:true,但我遇到了一个问题: Error: [$compile:ctreq] Controller 'testParent', required by directive 'testChildren', can't be found! http://errors.angularjs.org/1.2.0-rc.2/$compile/ctreq?p0=testParent&
Error: [$compile:ctreq] Controller 'testParent', required by directive 'testChildren', can't be found!
http://errors.angularjs.org/1.2.0-rc.2/$compile/ctreq?p0=testParent&p1=testChildren
at http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:78:12
at getControllers (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:4981:19)
at nodeLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:5122:35)
at compositeLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:4640:15)
at nodeLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:5115:24)
at compositeLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:4640:15)
at publicLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:4549:30)
at http://127.0.0.1/static/lib/angular/1.2.0rc2/angular-route.js:854:15
at publicLinkFn (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular.js:4548:29)
at update (http://127.0.0.1/static/lib/angular/1.2.0rc2/angular-route.js:832:13) <div test-children="">
谁能告诉我发生了什么?父指令必须提供一个控制器,然后作为子指令链接函数的可选第四个参数传入
angular.module('app', [])
.directive('testParent', [function() {
return {
restrict: 'EA',
controller: function() {
//... must include a controller in parent
this.doSomething = () => {}
}
}
}])
.directive('testChildren', [function() {
return {
restrict: 'EA',
require: '^testParent',
link: function(scope, element, attr, parent) {
parent.doSomething()
}
}
}])
用于此的HTML模板?我在v1.4.8中遇到了完全相同的问题。我已经为父指令提供了一个控制器。我已使用
.controller(…)
公开了模块中的控制器。我仍然得到这个错误。我期待着看到这个答案与工作示例代码。
angular.module('app', [])
.directive('testParent', [function() {
return {
restrict: 'EA',
controller: function() {
//... must include a controller in parent
this.doSomething = () => {}
}
}
}])
.directive('testChildren', [function() {
return {
restrict: 'EA',
require: '^testParent',
link: function(scope, element, attr, parent) {
parent.doSomething()
}
}
}])