Is there a way to access the isolated scope's property in the directive tag? Let's take a look at a simplified example:
angular.module('app', [])
.controller('myController', function() {
var result_el = document.getElementById("result");
this.log = function(text) {
var p = document.createElement("p");
p.innerHTML = text;
result_el.appendChild(p);
}
})
.directive('myDirective', function() {
return {
restrict: 'E',
scope: {
'click_fn': '&myClick'
},
template: '<span ng-click="click_fn()">Click me!</span>',
link: function(scope, element) {
scope.my_prop = 'text property';
}
}
});
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<div ng-app="app" ng-controller="myController as mCtrl">
<my-directive my-click="mCtrl.log(my_prop)"></my-directive>
</div>
<div id="result"></div>
In this scenario, I am trying to retrieve the my_prop
property from the directive's scope. Is there a way to achieve this?