1

I'm pulling through a json file into my Ionic/Angular html file. I have transformed some lines of text into a button.

My plan is that when the user clicks the button, the html of that button is passed as an argument to the 'ng-click' function (on the button).

But I'm struggling to do this - despite Google/SO searches/reading through Angular docs.

My HTML for the two buttons is:

    <p><span class="button button-positive button-small" ng-click=personalBest()>{{workout[0].box.cfhackney.daily[0].strength.exercise[0].movement.type[0]}}</span></p>

When the file is run on the local server, the HTML text for the above button is "Deadlift"

     <p><span class="button button-positive button-small button-text" ng-click=personalBest()> {{workout[0].box.cfhackney.daily[0].strength.exercise[0].movement.type[1]}}</p>

When the file is run on the local server, the HTML text in the above button is "Squat"

I'ld like both Deadlift and Squat to be passed as arguments to the 'ng-click=personalBest()' function on the buttons.

How can I do this?

My github reference is https://github.com/elinnet/protocf (the html file is located at testapp/www/templates/tab-wod.html)

Many thanks.

Elia
  • 39
  • 4

1 Answers1

1

Have you tried this?:

<p>
    <span class="button button-positive button-small" ng-click=personalBest(workout[0].box.cfhackney.daily[0].strength.exercise[0].movement.type[0])>
        {{workout[0].box.cfhackney.daily[0].strength.exercise[0].movement.type[0]}}
    </span>
</p>

You might also be able to do:

<span class="button button-positive button-small" ng-click=personalBest($event)>

And in your function call $event.target.innerHTML to get the innerHTML.

See this answer for a more thorough implementation of this idea.

Carson Crane
  • 1,197
  • 8
  • 15
  • Hi Carson - I've just tried it and it works. But is there a better way to get to the html value ? As the data call in the mustaches will likely change and I'm not sure how I would automatically update the ng-click argument – Elia Oct 26 '15 at 20:53
  • 1
    @Elia I edited my answer with another idea on how to do it. – Carson Crane Oct 26 '15 at 21:09