I have two separated directives. If some condition is evaluated to true
I have to call second directive inside first.
myDirectives.directive('first', function() {
return {
restrict: "E",
templateUrl: "Views/_first.html",
require: "ngModel",
scope: {
functiontocall: "&",
}
}
});
In HTML I'm calling directive as following:
<first ng-model="model.FirstDTO"
functiontocall="someFunctionForAsyncData(val)"></first>
Second directive is same, just with different html and passed function. I've omit additional data passed to directive which is not important for my current problem.
Now, I must call second directive inside first, so I've added additional function which is passed to first directive:
myDirectives.directive('first', function() {
return {
restrict: "E",
templateUrl: "Views/_first.html",
require: "ngModel",
scope: {
functiontocall: "&",
functionforseconddirective: "&"
}
}
});
How can I, inside my first directive make something like this bellow, pass function that is passed to first directive to another one (it's not working now):
<second ng-model="secondModel"
secondFn="functionforseconddirective(val)"></second>
Just to state that this is special case where these two directive are nested, I have couple of places inside code where I call each of them separately, so I would like solution to this specific situation, but not affecting all normal places in code where both of them are working correctly.
Update: jsfiddler: http://jsfiddle.net/kujg10fL/1/ I would like that click on second button display expected msg
Well. you did now show enough information to create a full qualified answer. I think
functionforseconddirective()
is defined in your controller. In that way you don't need to parse this funtion from one directive to another. You need atrigger
and you need to parse thevalue
from on directive to enougher like in this demo fiddle.View
AngularJS application
Updated answer based on your fiddle
Please check this demo fiddle.
View
AngularJS application