I have this controller with directive inside my html code. The directive have scope value I would like access from the parent controller and show in the html. Hope my example code give you a simple overview of what I'm trying to achieve.
I know this work using $rootScope.showvalue = 'pass text'; in the directive works but don't know if this is the best solution.
app.directive('customdir', [function() {
return {
restrict: "E",
scope: {
showvalue: "="
},
link: function(scope, el, attrs) {
scope.showvalue = 'pass text';
}
};
}]);
app.controller('mycontroller', function($scope) {
alert($scope.showvalue);
});
<html>
<div ng-controller="mycontroller">
<custom-dir></custom-dir>
/* Show scope value from custom dir */
{{showvalue}}
</div>
</html>