Answer the question
In order to leave comments, you need to log in
How to pass a function from a controller to a directive?
I have a function in a test controller. And I need to pass it to the directive and call it there.
directive looks like this
/** @ngInject */
function segment() {
return {
replace: true,
link: link,
restrict: 'E',
scope: {},
bindToController: {
segments: '=',
type: '@'
},
templateUrl: 'app/audience/segment.template.html',
controller: SegmentDirectiveController,
controllerAs: 'ctrl'
};
function link(scope, el, attr, ngModel) {
}
}
/** @ngInject */
function SegmentDirectiveController() {
function removeSegment(segment, type) {
// вот тут я хочу вызывать эту функцию.
}
}
Answer the question
In order to leave comments, you need to log in
{
bindToController: {
segments: '=',
type: '@',
onRemoveSegment: '&'
}
}
function removeSegment(segment, type) {
directiveController.onRemoveSegment({$someInformation: 'Segment ' + segment + ' removed'});
}
this.segmentRemoved = function($someInformation) {
console.log('Callback function ivoked with', $someInformation);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question