angularjs - call method from directive to controller -


i want call function in controller directive.

my directive

.directive('multecs', ['$http', function($http){     return{         restrict: 'a',         replace:false,         link: function(scope, elem, attr){             scope.addtoarray();         }     } }]); 

method in controller

$scope.addtoarray = function(){     console.log('method called'); } 

try passing in function want call directive.

 .directive('multecs', ['$http', function($http){      return{          restrict: 'a',          replace:false,          scope : {              myfunctiontocall : '='          },          link: function(scope, elem, attr){              scope.myfunctiontocall();          }      }  }]); 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -