Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

107
Views
How to pass parameters to a typescript function from html?

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>
7 months ago · Juan Pablo Isaza
3 answers
Answer question

0

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);
}
7 months ago · Juan Pablo Isaza Report

0

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>
7 months ago · Juan Pablo Isaza Report

0

try this

<ng-container *ngFor = "let user of users" >
    <button (click)="getdata(user.id)" mat-raised-button color="primary">{{user.name}}</button>
</ng-container>
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.