As a newcomer to AngularJS, I am exploring the creation of directives and how to invoke functions from the parent scope within them. While I have successfully achieved this, I am now grappling with the challenge of passing data from the isolate scope via an expression to the parent scope. The explanation provided in the Angular Developer guide has left me a bit perplexed.
Here is an example of the directive:
app.directive('myDir', function() {
return {
restrict: 'E',
template: '<div ng-click="parentFunc(someValue)"><div>',
scope: {
parentProp: '=property',
parentFunc: '&func'
},
link: function(scope, element, attrs) {
}
}
});
The corresponding markup looks like this:
<my-dir prop="foo" func="bar(someValue)"></my-dir>
And here's how it would be handled in the controller:
app.controller('TstCtrl', function($scope) {
$scope.foo = 'test';
$scope.bar = function(value) {
console.log(value);
};
});
Your insights and assistance on this matter are greatly appreciated!