How to add ng-click handler dynamically (from directive)?

6,085 views
Skip to first unread message

solo117

unread,
Aug 16, 2013, 8:00:36 AM8/16/13
to ang...@googlegroups.com
Hello, everybody!

How can I add "ng-click" handler into element dynamically?
There is a plnkr

This directive is rendered as
<input type="button" set-on-click="" value="click me!" ng-click="clickMe()">
But it doesn't work at all!
Thanks.

Devon Tucker

unread,
Aug 16, 2013, 5:05:43 PM8/16/13
to ang...@googlegroups.com
I try never to question WHY someone wants to do something, but I'm not sure why you would want to do this. If you absolutely have to add another directive in the linking function you'll have to invoke the $compile service, like so:


Notice I had to remove the set-on-click attribute before compilation, since without doing so the compilation would get stuck in an infinite loop trying to compile set-on-click. 
Reply all
Reply to author
Forward
0 new messages