嗨试图要求对同一元素。根据角度文档,这是可能的。角度指令要求在同一元素上
A^prefix would make the directive look for the controller on its own element or its parents; without any prefix, the directive would look on its own element only.
继解释。我有两个指令,myD和myC ...希望能够从myC的链接ctrl属性访问myD。
我已经包含一个指向我的codepen示例的链接。
var app = angular.module("app",[]);
app.directive("myD", function() {
return {
restrict : "E",
template : "<b>myd</d>"
}
});
app.directive("myC", function() {
return {
require : "myD",
restrict : "A",
link : function (scope, attr, ele, ctrl) {
alert(JSON.stringify(ctrl));
}
}
});
<div ng-app="app">
<my-d my-c></my-d>
</div>
http://codepen.io/mantisimo/pen/KWOxeg
得到以下错误:
Error: [$compile:ctreq] Controller 'myD', required by directive 'myC', can't be found!
把控制器:function(){}指令里面'myD'? – ABOS
谢谢你......真的只是想到了它! :-) – Mantisimo