Retrieve the data from the mat-checkbox

My goal is to retrieve a value from a mat-checkbox, but the issue is that we only get boolean expression instead of the string value. Here's an example snippet of what I'm looking for:

<mat-checkbox formControlName="cb2" <strong>value="success"</strong> id="cb2" name="cb2"  (change)="updateCheckBox()">CB2

We specifically require the value 'success'
I'm currently working with angular 10.0.5 on Windows 10.

Warm regards.

Answer №1

Here's a simple method to accomplish this task.

<input type="checkbox" #customCheckbox formControlName="customCheckbox" value="true" id="customCheckbox" name="customCheckbox" (change)="updateCustomCheckbox(customCheckbox)">

Next, in your TypeScript file

isChecked: boolean;
updateCustomCheckbox(event) {
this.isChecked = !event.checked;
}

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

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...

What is the best way to simulate an ActivatedRouteSnapshot?

Currently, I am working on unit testing the code snippet below: ngOnInit() { this.router.events.subscribe((val) => { if (val instanceof ActivationEnd && val.snapshot) { this.selectedLanguageCode = val.snapshot.queryParams ...

What is the best way to check for duplicate email input when using knex?

Currently, I am in the process of developing an application using node.js, knex.js, typescript, zod, and fastify. My main focus is on validating emails during user registration. If a duplicate email is inserted, I want the system to throw a 401 (conflict) ...

Angular 2/NPM: setting up a new directory with all the necessary files for running the application

I'm feeling a bit frustrated, but I'm giving it a shot anyway. Our goal is to create a TypeScript Angular 2 hello world app that we can use as the front end for a Spring app. Currently, we're using the Angular 2 quickstart as our foundation ...

Iterate through the array and show the information using Angular

enter image description hereI am a beginner in Angular and I am looking to iterate through an array in Angular. The array contains the following elements: "ticketsdetectives":[10,11,12,13] My goal is to display this data similar to the following ...

Guide to linking properties to Bootstrap 5 components within Angular

I am currently using Angular 13 along with Bootstrap 5. The bootstrap elements are functioning perfectly fine for static content. <button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popo ...

Creating assets from typescript plugins in Angular 6: A comprehensive guide

Situation I am currently in the process of migrating from Angular 4 and Angular Seed to Angular 6 and Angular CLI. Challenge One issue I am facing is with dynamic loading of plugins within a component using SystemJS. SystemJS.import("client/plugins/" + ...

The specified dependency, * core-js/fn/symbol, could not be located

I am in the process of developing a Vue.js application with Vuex and have encountered some errors during the build. I attempted to resolve the issue by installing npm install --save core-js/fn/symbol, but unfortunately, it did not work as expected. https:/ ...

The information retrieved from the API is not appearing as expected within the Angular 9 ABP framework

I am facing an issue with populating data in my select control, which is located in the header child component. The data comes from an API, but for some reason, it is not displaying correctly. https://i.stack.imgur.com/6JMzn.png. ngOnInit() { thi ...

What are the benefits of using material-ui@next without the need for

Thinking about creating a project using material-ui@next, but trying to avoid using withStyles. However, encountering issues with the draft of TypeScript that includes the decorator @withStyles. This leads to one question - is it possible to use material ...

Exploring the capabilities of AngularJS2's formGroup and formControlName functionality

Exploring the world of AngularJS2, I recently created a sign-up page utilizing formGroup formControlName, but encountered an issue with passing null values to the object. HTML code: <div class="col-md-8 col-md-offset-2"> <form [formGroup]="m ...

Deliver the commitment to the data source connection settings in TypeORM

Is it possible to retrieve the datasource connection options from AWS Parameter Store instead of storing them as environment variables in a general JavaScript question? I am having difficulty finding a solution and seeking expert advice on this matter. Th ...

What steps can be taken to stop Internet Explorer from caching Ajax requests in Angular2 using TypeScript?

Imagine a situation where a user has 10 points. When they click a button, an ajax call is made to the server to update the user's points after they have been used. The server should send back 9 points, which is functioning correctly on all browsers ex ...

How can I effortlessly retrieve the Current Route Path Name in Angular?

I needed to find out the current route's path name and discovered this simple solution. this.route.snapshot.firstChild.url[0].path Is there a more efficient method for achieving this? Appreciate any advice! ...

Ways to identify if there is a problem with the Firestore connection

Can anyone help me understand how I can use angularfire2 to check the accessibility of the cloud firestore database and retrieve collection values? If accessing the cloud database fails, I want to be able to retrieve local data instead. This is an exampl ...

Go through each item in the array and change its properties

When retrieving data from the database, I receive the following information: "Data": [{ "mainData": [{ "_id": ObjectId("5ab63b22d012ea2bc0bb7e9b"), "date": "2018-03-24" }], "files": [ { "_id": ObjectId("5ab63b22d012ea2bc0bb7e9d"), ...

Encountered an issue in Angular where the property 'value' is undefined and cannot be read

I am new to learning Angular and have come across an issue with my form. Here is the HTML form code: <mat-form-field class="tp-full-width" style="padding-left: 20px;"> <input #equiId formControlName="equiId" matInput placeholder="Equipment ...

Is there a way to turn off the "defer" feature in an Angular build?

After compiling my Angular project, I noticed that the compiler automatically adds the "defer" attribute to the script tag in my "index.html" file. However, I need to disable this feature. Is there a way to do it? I am currently working with Angular versi ...

Accessing nested JSON objects with key-value pairs

I have a method in my .ts file that displays keys but doesn't fetch nested JSON data. generateArr(obj) { return Object.keys(obj).map((key) => { console.log(key, obj[key]); return {key: key, value: obj[key]}; }); } Here is the HTML code I&apo ...

Creating an Angular feature module with the aim of converting it into an Angular library

Currently, I am developing an angular feature module as a library to enable us to create individual modules without the need to rebuild the entire angular application. While this approach seems to be functioning well, my question is whether it is conside ...