I am fetching my users
in the form of a JSONArray and I want to show the data of each user when clicked on their names. but I am not able to pass the user.id
into the function.
<ng-container *ngFor = "let user of users" >
<button (onclick)="getdata(user.id)" mat-raised-button color="primary">{{user.name}}</button>
</ng-container>
CodePudding user response:
Can you please try the same with using only click() instead on onclick()
<ng-container *ngFor = "let user of users" >
<button (click)="getdata(user.id)" mat-raised-button color="primary">{{user.name}}</button>
</ng-container>
CodePudding user response:
Its angular use (click)
instead of (onclick)
<ng-container *ngFor="let user of users">
<button (click)="getdata(user.id)" mat-raised-button color="primary">
{{ user.name }}
</button>
</ng-container>
getdata(id) {
console.log(id);
}
CodePudding user response:
try this
<ng-container *ngFor = "let user of users" >
<button (click)="getdata(user.id)" mat-raised-button color="primary">{{user.name}}</button>
</ng-container>