Home > other >  How can i use an {{ }} into a function
How can i use an {{ }} into a function

Time:10-14

im trying to call a function but one on mi parameters are in an api, so i need to use an {{}} this is an example of mi code:

<button  (click)='goToPage("Players", {{team.TeamID}} )'> Informacion</button>

i tried this but doesnt work

<button  id = {{team.TeamID}} #teamid (click)='goToPage("Players", $event.target )'> Informacion 

CodePudding user response:

You can just remove your braces {{ }} and do the following :

<button  (click)='goToPage("Players", team.TeamID)'> Informacion</button>

Braces are only use to modify HTML content. Here you are using a javascript function.

CodePudding user response:

If you have to pass variable in to a function from the html you do not need to interpolations ({{}}). u can just use the variable or API response as a parameter to a method. but you need to declare that variable using public access modifier. Bellow I have correct your problem.

<button id = "{{team.TeamID}}" #teamid (click)="goToPage('Players', team.TeamID )"> Informacion

  • Related