需要父指令控制器的AngularJS指令控制器?
发布于 2021-02-01 10:21:18
我可能会考虑将其完全倒退,但是我正在尝试制作三个嵌套指令,让它们称为:屏幕,组件和小部件。我希望窗口小部件能够触发组件中的某些行为,从而触发屏幕中的某些行为。所以:
.directive('screen', function() {
return {
scope: true,
controller: function() {
this.doSomethingScreeny = function() {
alert("screeny!");
}
}
}
})
.directive('component', function() {
return {
scope: true,
controller: function() {
this.componentFunction = function() {
WHAT.doSomethingScreeny();
}
}
}
})
.directive('widget', function() {
return {
scope: true,
require: "^component",
link: function(scope, element, attrs, componentCtrl) {
scope.widgetIt = function() {
componentCtrl.componentFunction();
};
}
}
})
<div screen>
<div component>
<div widget>
<button ng-click="widgetIt()">Woo Hoo</button>
</div>
</div>
</div>
我可以使用来在小部件的链接fn中要求父组件require: "^component"
,但是如何进一步使组件控制器访问其包含的屏幕呢?
我需要的是WHAT in组件,因此,当您单击小部件的按钮时,它会发出“ screeny!”警报。
谢谢。
关注者
0
被浏览
83