Beimar Rojas
Beimar Rojas

Reputation: 55

Identify the p-checkbox where an event occurs in Angular

I would like to know if there is a way to identify my checkbox, along with the event that occurs when it is selected, that is, if I can put a type of ID and pass it to my .ts file, along with the true or false that responds to me the event.

<p-checkbox name="reviewed" inputId="reviewed" [(ngModel)]="data.reviewed"
  [binary]="true" (onChange)="checkValue(data.reviewed)">
</p-checkbox>
checkValue(event: any){
    //here I want to recerive the checkbox ID;
    console.log(event);
}

Upvotes: 3

Views: 14466

Answers (1)

Muhammed Albarmavi
Muhammed Albarmavi

Reputation: 24464

you can create a template variable for the checkbox component then pass the inputId

<p-checkbox name="reviewed" inputId="reviewed" [(ngModel)]="data.reviewed"
  [binary]="true" (onChange)="checkValue(checkElm.inputId ,data.reviewed)" #checkElm>
</p-checkbox>

component.ts

checkValue(id,event: any){
  //here I want to recerive the checkbox ID;
}

if you want you can just pass the id as hardcoded value

<p-checkbox name="reviewed" inputId="reviewed" [(ngModel)]="data.reviewed"
  [binary]="true" (onChange)="checkValue('reviewed',data.reviewed)" >
</p-checkbox>

Upvotes: 4

Related Questions