angularjs - Click event not firing when attached in directive compile -



angularjs - Click event not firing when attached in directive compile -

i'm trying attach click event li's within of compile function , can see ng-click beingness nowadays in dom event not fired.

compile:function (elem, attrs){ //elem.find('li').attr('data-ng-click', 'hello()'); elem.find('li').attr('ng-click', "hello($event)"); homecoming function(scope, elem, attrs) { scope.hello = function ($event) { console.log($event); alert('click triggered') }; }

plnkr : http://plnkr.co/edit/o8jyjm?p=preview

just adding attribute directive won't cause processed. every element going have directives in needs run through $compile link function created , link function needs called scope object passed (typically created using $rootscope.new()). said there typically easier ways accomplish want using ng-click in template (which compiled) or using element.bind("click",function(evt){}). i'll prepare plunkr in bit here too.

angularjs

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -