randombits
randombits

Reputation: 48490

How to invoke this Angular method that's bound to ng-click

I'm inspecting the DOM on an Angular application and trying to figure out how I can reproduce one of the events that's bound to a button via the console. The button looks like this:

<button class="button tiny text player-add-button" ng-class="{ 'player-add-button': !player.inLineup, 'player-remove-button': player.inLineup }" ng-click="player.inLineup ? draft.rosterRemove(player) : draft.rosterAdd(player)">

What I'm trying to access here is draft.rosterAdd(). The problem is, this is a table, and there's multiple buttons and player is changing for every button. I'm not entirely sure how to define player here, even if I get into the scope of of the draft object, to pass it in as an argument to rosterAdd()

What's the best way to figure out how I can define player so that I can invoke draft.rosterAdd(player) for all of the players I want to add via the console?

Upvotes: 0

Views: 64

Answers (1)

Michael Benford
Michael Benford

Reputation: 14114

Try this (in Chrome):

  1. Right-click the desired button and select Inspect element;
  2. Open the console tab (make sure the button markup remains selected);
  3. Type draft = angular.element($0).scope().draft;
  4. Type player = angular.element($0).scope().player.

Now you should be able to see how player is structured and call draft.roasterAdd() passing whatever you want.

Some useful references about the code above:

Upvotes: 1

Related Questions