I am trying to send data of a directive link function from a controller when I used ng-clicked , but I was unable to send data to a directive, the directive calls when the page first loads
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);
source share