Fra96
Fra96

Reputation: 55

how to Use element read by ngfor as function parameter

I have this angular peace of code:

<table>
        <tr>
            <th style="width:50%"><b>List rooms </b></th>
            <th></th>
        </tr>

        <tr *ngFor="let room of list_room">
            <td><b> {{room}}</b> </td>
            <td><button (click)="joinRoom()">JOIN</button></td>

        </tr>
</table>

I need to take the string content of {{room}} and pass it as a parameter to the function joinRoom().

I tried with this link: Send *ngFor value as parameter on click

I changed my code with:

<td><button [(ngModel)]="room" (click)="joinRoom(room)">JOIN</button></td>

but I have a compile error.

How can I do?

Upvotes: 1

Views: 252

Answers (1)

Nostix
Nostix

Reputation: 41

You need to remove the ngModel.

Using this should work:

<button (click)="joinRoom(room)">JOIN</button></td>

Example: https://stackblitz.com/edit/angular-xqnent

Upvotes: 1

Related Questions