【发布时间】:2014-12-30 01:28:39
【问题描述】:
所以当在子指令中使用指令属性require: '^ParentCtrl' 时,我总是完全反向执行此操作。然后使用 require 调用父函数;但是,我需要反过来做。
问题:
如何从父指令触发子指令中函数的执行。
注意:
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 () {...};
}
})
【问题讨论】:
标签: javascript angularjs angularjs-directive