I am trying to send the data to directive link function from controller when i used ng-clicked
, but I failed to send the data to directive, the directive is calling when the page was loading at first time
here is my html code
<h2 ng-click="clickMe(somedata)"> click </h2>
<my-directive my-key="myVal"> </my-directive>
here is my controller
.controller('myController',function($scope){
$scope.clickMe=function(somedata){
$scope.myVal=somedata;
};
});
my directive
.directive('myDirective',function(){
return{
restrict:'E',
scope:{
myKey:'='
},
templateUrl:'exampleTempl.html',
controller:'myController',
link:function(scope,elem,attr){
console.log(scope.myKey); // getting undefined
console.log(scope.myVal); //here i want the data from controller when i clicked on ng-click
}
}
});