Programmatically deselecting a radio button in code

How can I programmatically uncheck the radio button posted below using TypeScript? I attempted to set the value of averageHeight to false, but that did not result in the radio button being unchecked. Can you please provide guidance on how to achieve this?

HTML:

<div id="idRadioButtonForAverageHeightDivision">
    <input [value]="0" [(ngModel)]="iOperationPasser.averageHeight" name="radioGroupForOperations" type="radio" clrCheckbox  (change)="toggleShowAverageHeight()"  [(checked)]="averageHeight"/>
    <label id="operation-average-height">
        {{ "SITE.AREAS_OF_COVERAGE_FOR_THRESHOLD.OPERATION_AVERAGE_HEIGHT" | translate }} 
        <button class="btn btn-sm btn-icon" (click)="showInformation('SERVICE_DIST_4_AGRI')">
            <clr-icon shape="help-info" class="is-solid"></clr-icon>
        </button>
    </label>
</div>

Answer №1

The standard behavior of the radio input is to remain checked once selected.

To modify its attributes, you can use binding or leverage Angular functionality by accessing the checked property and modifying it accordingly.

For example:

<input type="radio" value="exm" #radio />


// access the input using a local variable in the template
<button (click)="radio.checked=false">
    uncheck
</button>

Alternatively, you can do the following:

<input type="radio" value="exm" [checked]="term" />


// this will toggle the checked status on click
<button (click)="toggle()">
    uncheck
</button>


TS FILE ----------------------
public term: boolean = false

toggle(){
  this.term = !this.term

}

If you need to access the value property, the process remains similar:

<input type="radio" [value]="value" />


TS FILE ----------------------
// any changes to the value will reflect in the template. ngModel is not useful for non-text inputs.
public value: string = 'Value here'

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

Curvature Factor equals Overflow of Color

After trying various solutions like "background-clip: padding-box;" to address the issue of background color bleeding outside of the border, I'm still not completely satisfied with the result. Is there a more effective fix for this problem? Check out ...

The 'isMounted' property is not found in the 'ErrorBoundary' type

I'm currently working on my TypeScript skills and I've come across a bug that's hindering my progress: Property 'isMounted' does not exist on type 'ErrorBoundary'. The following is my Error Boundary component: // Reac ...

Choosing from a Variety of Options from a Dropdown Menu

Hello, I have a question that I've asked before but need to simplify now. Please provide some logic for the following scenario: First dropdown list - Contains Class-1, Class-2, Class-3, etc. Second dropdown list - Depends on the selected class. If Cla ...

Creating a full-width row and columns layout using CSS Flex Box styling

Hello my fellow coding enthusiasts! I'm trying to create a simple box layout using flexbox, but I'm struggling to get it just right. The goal is to have a row with two columns within one container. Here's what I'm aiming for: Essentia ...

Ways to retrieve the following angular.callbacks.counter within angular2

In order to use the Yelp API, a signature is required. This signature needs to be generated by passing all the parameters for the URL that will be used. Simply put, when querying the API using jsonp, the key was to first generate the next JSONP callback I ...

Nest.js: initializing properties from a superclass in a controller

I have a question about unit testing controllers in the Nest.js framework. My issue is that the property from a superclass is not initialized in the controller class when creating a test module. Here is an example of the code I am referring to: export cl ...

Angular mat-form-field not accepting placeholder value

It seems that the placeholder for input which reads "Search Here" is not functioning properly. Could it be because it's contained within a mat-form-field? The only CSS rules defined for the input class are: .search-input{ width:100%; } Any a ...

Electron encountered an error while attempting to deserialize cloned data because of an invalid or unsupported version

I have developed an Angular application that is currently running as a standalone. Now, I am attempting to create an Electron app where the main functionality just involves loading the URL 'http://localhost:4200/'. However, please note that this ...

What steps do I need to take to ensure my TypeScript module in npm can be easily used in a

I recently developed a module that captures keypressed input on a document to detect events from a physical barcode reader acting as a keyboard. You can find the source code here: https://github.com/tii-bruno/physical-barcode-reader-observer The npm mod ...

Making changes to a specific row in a datatable within a Flask project

I need help with creating an edit function for my data table. I only require front-end and a bit of JS (Ajax) code to send the data. The picture below shows what I am trying to achieve: https://i.sstatic.net/9QDXl.png Here is how my data table looks like: ...

Utilizing a Bootstrap column design with two columns in place - one column set at a fixed width while the second column stretches across the remaining

Need help with adjusting two columns on a webpage? The right column is fixed at 300px width, while the left column should take up the remaining space. Using flex works well, but when adding a responsive ad to the left column, it extends beyond the availabl ...

Assistance with Parallax Mouse Movement, Using JQuery, HTML, and CSS

As a newcomer to JQuery, I decided to experiment with creating a parallax background effect using the mousemove function. By utilizing event.pageX to generate a variable for adjusting the background position, I was able to achieve the desired result. Alth ...

Adding a JQuery Plugin to Brunch 2.8

I am currently working on a Brunch project with version 2.8.2. This particular version of Brunch is compatible with front-end dependencies through NPM. Additionally, I have integrated the Typescript Brunch plugin and successfully implemented import $ = req ...

Utilizing media queries and page width in a Moodle theme designed with Bootstrap framework

I currently have my LMS set up with Moodle 4 and the boost theme which is based on bootstrap (github) However, the default page layout appears very narrow on all devices and I would like to utilize the responsive design features of Bootstrap for different ...

How can I create an HTML link that opens a drop-down menu with form functionality?

Feeling a bit perplexed here as I'm not entirely sure how to label this issue... If you're familiar with the Facebook interface, I'm trying to develop a feature similar to the "DOWNWARD ARROW" icon found next to the "comments" or "status" b ...

Having issues with CSS vertical margin not functioning properly

#outline { background: green; height: 96vh; width: 96vh; } #box { background: white; height: 86vh; width: 86vh; margin: 5vh; border: 1px solid #DDDDDD; overflow: hidden; } <div id="outlin ...

Can an application be developed with OAuth2 that is role-based?

I am working on developing an application that combines Angular frontend and Spring Boot backend with OAuth2 authentication. My main challenge is figuring out how to retrieve the user's roles on the frontend. I want to be able to display role-based c ...

Guide on calculating the total of an object's attributes in Angular

Given a JSON object structured as follows: { "baskets": [{ "id": 127, "name": "name 1", "kpIs": [{ "id": 419, "name": var a1, "incentive": 0, "ta ...

When there are additional parameters following .../foo.png/, the Img-src does not properly resolve the URL

Here is the link to my URL that I am trying to use: Whenever I try to open this link in my browser, it displays a raw image. However, when I reference it in an <img src> tag, I do not get the desired image returned. Strangely, if I remove everything ...

Tapping on the emphasized hyperlink within an unorganized roster

I am currently working on a page and have encountered an issue. The problem lies in the fact that users must click on a link before they are redirected to the target page. Is there a way to make the highlighted box for each of those links active so it resp ...