因此,在子指令中使用僞指令屬性require: '^ParentCtrl'
時,我總是反向操作。使用require來調用父函數;不過,我需要做相反的事情。在父指令中觸發子指令中的函數[angularJS]
問:
如何觸發從父指令在孩子指示功能的執行。
注意: 1.兒童指令沒有功能是在link:
2.基本上我想要一個反向要求。
家長指令:
'use strict';
angular.module('carouselApp')
.directive('waCarousel', function() {
return {
templateUrl: 'views/carousel/wa.carousel.html',
controller: function($scope) {
var self = this;
// this function is being called based on how many pages there are
self.carouselElLoaded = function(result) {
var count = 1;
Carousel.params.pageRenderedLength += count;
//when all the pages are loaded
if (Carousel.params.pageRenderedLength === Carousel.params.pageLength) {
Carousel.params.carouselReady = true;
// !!!!!!!! Trigger will go here!!!!!!!!!//
ChildCtrl.drawHotspots(); // (**for placement only**)
} else {
Carousel.params.carouselReady = false;
}
};
}
}
})
兒童指令:
'use strict';
angular.module('carouselApp')
.directive('waHotspots', function() {
return {
require: '^waCarousel',
link: function (scope, element, attrs, ctrl) {
//call this directive based on how
scope.drawHotspots = function() {...};
}
})
你說鬆散地耦合指令,但你的例子似乎非常緊密耦合。 – tic