Feasible to dynamically bind function to ng-click?

381 views
Skip to first unread message

Chris Dieringer

unread,
May 27, 2014, 7:35:15 PM5/27/14
to ang...@googlegroups.com
Hi all:

I have a repeater, that looks roughly like:

<li ng-repeat="(id, button) in modalConfig.buttons">
  <a href="#">
    <span ng-click="button.action()" class="button modal-button-{{id}}">{{button.text}}</span>
  </a>
</li>

Where a button object looks like: {
  id: 'id',
  action: function(xxx) { ... }
}

When this runs, I get an "illegal invocation" error.  What gives?  Am I not permitted to pass functions dynamically into ng-click?

Thanks!

Chris

Chris Dieringer

unread,
May 27, 2014, 8:14:35 PM5/27/14
to ang...@googlegroups.com
More specifically, the error occurs when I click the button* and the function is attempted to be executed.

Eric Eslinger

unread,
May 28, 2014, 2:12:21 PM5/28/14
to ang...@googlegroups.com
I do that kind of thing all the time, so I'd say: maybe look into the button object itself? Can you post a minimal-case plunker? 

e


On Tue, May 27, 2014 at 5:14 PM, Chris Dieringer <christophe...@gmail.com> wrote:
More specifically, the error occurs when I click the button* and the function is attempted to be executed.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Chris Dieringer

unread,
May 31, 2014, 11:30:01 AM5/31/14
to ang...@googlegroups.com
Hi Eric:

Thanks for the willingness.  In making a fiddle, apparently I convinced myself otherwise.  Working fiddle here:


Shoot.  Must have been fighting some other issue!

-Chris

Eric Eslinger

unread,
May 31, 2014, 12:48:42 PM5/31/14
to ang...@googlegroups.com
That happens to me all the time, so much so that I usually end up figuring out the problem that I wanted to ask of a SO or list post in crafting the minimum-replicable case for the post. It may also be some kind of event conflict between the <a> element containing the ng-click, and the ng-click itself.

e


--
Reply all
Reply to author
Forward
0 new messages