Discovering the specific p-checkbox in Angular where an event takes place

Is there a way to assign an ID to my checkbox element and retrieve it in my .ts file when the checkbox is selected? I want to pass this ID along with the true or false value that indicates if the checkbox is checked. Here's an example code snippet:

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

Answer №1

If you want to customize the checkbox component, consider creating a template variable and passing the inputId as shown below:

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

In your component.ts file:

checkValue(id,event: any){
  // Add logic here to receive and handle the checkbox ID
}

If preferred, you can simply pass the id as a hardcoded value like this:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The 'Element[]' type is lacking certain properties when dealing with react children

In my code, there is a parent component passing down its children to a child component. These children can be either single nodes or arrays of nodes, and the ChildComponent renders them differently based on their type. However, when I try to render the Chi ...

Having trouble importing a TypeScript module from the global node_modules directory

I have a library folder located in the global node modules directory with a file named index.ts inside the library/src folder //inside index.ts export * from './components/button.component'; Now I am trying to import this into my angular-cli ap ...

TypeScript enabled npm package

I am currently developing a npm module using TypeScript. Within my library, I have the following directory structure: . ├── README.md ├── dist │ ├── index.d.ts │ └── index.js ├── lib │ └── index.ts ├── ...

The combination of Object.keys() and the find function

Having trouble figuring out why I'm getting an error when attempting to use ES6 .find on the following data in order to retrieve the record with id number 3. { {id:10,title:'Dairy & Eggs'} {id:7,title:'Laundry & Household'} {id ...

React.js: You cannot call this expression. The type 'never' does not have any call signatures

Could someone help me troubleshoot the error I'm encountering with useStyles? It seems to be related to Typescript. Here's the line causing the issue: const classes = useStyles(); import React from "react"; import { makeStyles } from & ...

Decoding the mysteries of a ZoneAwareError: A guide to unraveling the enigma

Within my Angular 2 application, I utilize a resolve guard that performs an XHR request and throws a custom error if the request fails: return this.service.getProduct (id) .catch (err => Observable.throw(new MyError(err.message, route, 500, err))); ...

What is the reason for Angular HttpClient to substitute " " with "↵"?

When using the HttpClient to send a POST body that is either a string or an object with a string value, any instances of "\n" are being replaced with "↵", especially in Chrome 73. Interestingly, in Firefox, it seems like "↵" is displayed as " " wh ...

Issue encountered while attempting to install dependencies using Stackblitz

I recently attempted to add ng-select to my StackBlitz project by including it in the dependencies section and importing it in app.module.ts. However, I encountered an error. You can view my code here. import { NgModule } from "@angular/core"; import { Br ...

Firebase authentication link for email sign-in in Angularfire is invalid

Currently, I am utilizing the signInWithEmailLink wrapper from AngularFire for Firebase authentication. Despite providing a valid email address and return URL as arguments, an error is being thrown stating "Invalid email link!" without even initiating any ...

Instead of relying on Vue TypeScript, we are leveraging IntelliJ with TypeScript 5.0.3 to compile our Vue project

My current version of IntelliJ IDEA is 2023.1 (Ultimate Edition) Build #IU-231.8109.175, released on March 28, 2023. I am facing an issue where my project fails to compile using "Vue TypeScript", resulting in some type mismatches being overlooked. In the ...

Find the combined key names in an object where the values can be accessed by index

I am currently working on creating a function called indexByProp, which will only allow the selection of props to index by if they are strings, numbers, or symbols. This particular issue is related to https://github.com/microsoft/TypeScript/issues/33521. ...

The URL for my JSON file cannot be located on my Angular server

Hey there! I'm currently working on setting up a server that will be pulling product data from a JSON file using HTTP. However, I've encountered an issue during the application build process where this error message pops up: Failed to load resou ...

What are the steps to execute jest in an AWS Lambda environment?

I'm looking to execute my end-to-end test post-deployment for the ability to revert in case of any issues. I've followed the guidelines outlined in this particular blog post. Below is my lambda function: export async function testLambda(event: A ...

Generics in Typescript interfaces

I'm trying to grasp the meaning of T = {} within this TypeScript interface. I've searched for documentation on this usage but haven't found anything specific. How does it differ from simply using T? interface CustomProps<T = {}> { ...

Setting the dispatch type in Redux using Typescript

I'm new to typescript and I'm trying to figure out what type should be assigned to the dispatch function. Currently, I am using 'any', but is there a way to map all actions to it? Here's how my code looks like: interface PropType ...

Angular 4 file upload verification: Ensuring safe and secure uploads

Is there a recommended method to validate the file type when uploading a file in an Angular 4 form? Are there any simple ways to accomplish this task? ...

Improve the way you manage the active selection of a button

ts isDayClicked: { [key: number]: boolean } = {}; constructor() { } setSelectedDay(day: string, index: number): void { switch (index) { case 0: this.isDayClicked[0] = true; this.isDayClicked[1] = false; this.isDay ...

Oops! An issue occurred while trying to compile the file constructor.d.ts in the common-behaviors folder of @angular/material/core. The error message received was: "error TS1005: ';'

Switching from Bootstrap to Angular Material caused an unexpected error when trying to run ng serve: Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';' expected. The errors encountered include: ...

Designing a personalized Angular package for components

I am currently working on developing reusable components that can be utilized across multiple teams. After creating a new Angular project, I went ahead and published it to Azure DevOps artifacts. When attempting to use the component in another project, I ...

Is Intellisense within HTML not available in SvelteKit when using TypeScript?

Having trouble with intellisense inside HTML for a simple page component. Also, renaming properties breaks the code instead of updating references. Typescript version: 4.8.4 Below is the code snippet: <script lang="ts"> import type { Bl ...