Now I also want to get data(title) from a json file inside a button but somehow there is nothing happening, I thought it would be easy but hope you cn tell what I do wrong inside the button:
Ok, thanks, I’ve changed that part but still not working.
Weird thing is that in the form the part of NgModel is need to let it work there. NgModel is not for a button field without a form. Is NgModel usable without forms or is there something else that I have to use in a button field to pass the data?
<div *ngFor="let fruit of fruits">
<label>{{fruit}}</label>
<button (click)="chooseFruit(fruit)">choose</button>
</div>
The point is that you can pass template variables (like fruit in this example) to click handlers. While $event is probably the most common idiom, it’s by no means the only possibility. You could even do (click)="chooseFruit(fruit, $event) if you need to (although that’s fairly rare).