Pass html page id inside ngFor to ts page

Asked

Viewed 822 times

1

I have a *ngFor of an array object, I want to pass the id inside the button to typescript to configure it as links in a modal. Follow the syntax I’m trying with no success:

<ion-item *ngFor="let item of itens">
    <ion-thumbnail item-left>
      <img src="../assets/img/{{item.img}}">
    </ion-thumbnail>
    <h2>{{item.nome}}</h2>
    <p>{{item.categ}}</p>
    <button id="{{item.id}}" ion-button clear item-right (click)="chamaProd()">ver</button>
  </ion-item>
  • and component controller? what code ?

  • It would just be (click)="chamaProd(item.id)", so in your controller the function would be called Prod(id) and that id is what was passed. Have you tried this? If you want to make an example.

1 answer

3


Try to do it that way:

HTML:

 (click)="chamaProd(item)" 

So you will pass the complete object from the list to your method chamaProd.

TS:

  chamaProd(item : <<Objeto da Lista>>){
.
. /* No corpo do metodo vc faz oque quiser, pois, vc tem a instancia do objeto clicado em tela */
}  

Browser other questions tagged

You are not signed in. Login or sign up in order to post.