I'm trying to work out how to toggle data from JSON when a user clicks a button on the UI. I am using Angular 2 for this.
The mark up looks like this:
<button type="button" (click)="changeOdds('odds')">odds</button>
<button type="button" (click)="changeOdds('fractionOdds')">fraction odds</button>
<button type="button" (click)="changeOdds('americanOdds')">american odds</button>
<div *ngFor="let marketOption of market.marketOptions">
<span>{{ marketOption.fractionOdds }}</span>
</div>
The JSON data looks like this:
"marketOptions": [
{
"americanOdds": -599,
"fractionOdds": "167/1000",
"odds": 1.167
}
]
So currently fractionOdds is displayed, but if a user clicks the button 'american odds' then 'americanOdds' should be displayed from the JSON. I would also need to save the user to a cookie/local storage to save the users selection. But im not sure if thats the best approach. Does anyone know how I can do this with angular 2, or know of any examples online?
EDIT:
Here is a link to the JSON object where 'marketOptions' is located
https://gist.github.com/fogofogo/f4b5ac9a765fc684e7e08b30221c6419