Is there a way to maintain the connection with the current controller when wrapping data with a directive?
I am facing an issue where the directive within the wrapped template loses connection with the outside controller, making it impossible to execute functions.
Custom Wrapping Directive:
myApp.directive('wrapContent', function() {
return {
restrict: "E",
scope: {
model: "=",
datas: "="
},
templateUrl: "./any/template.php",
link: function(scope, element, attr) {
// implementation
}
};
});
Directive Inside Wrapped Template:
myApp.directive('doAction', function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
$(elem).click(function(e) {
scope.$apply(attrs.doAction);
});
}
}
});
Controller:
lmsApp.controller('OutsideController', function ($scope){
$sope.sayHello = function() {
alert("hello");
};
});
HTML snippet where I want to trigger the function (template.php):
<div>
<do-action="sayHello()"></do-action>
</div>
How I call the wrapContent
directive which is located outside (Updated):
<div ng-controller="OutsideController">
<wrap-content model="any" datas="data_any"></wrap-content>
</div>
What is the solution to executing the sayHello()
function?
Your assistance is greatly appreciated. Thank you for all responses!