Clicking on an Angular mat-checkbox requires two clicks to toggle between checked and unchecked states

My checkboxes are populating dynamically, but I am facing an issue when trying to unselect them. It takes two clicks to uncheck the checkbox.

enter code here
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl">
        <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle matTreeNodePadding>
          <button mat-icon-button disabled></button>
          <mat-checkbox class="checklist-leaf-node"
                        [checked]="checklistSelection.isSelected(node)"
                        (change)="checklistSelection.toggle(node);">{{getValue(node)}}</mat-checkbox>
        </mat-tree-node>



        <mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
          <button mat-icon-button matTreeNodeToggle
                  [attr.aria-label]="'toggle ' + node.filename">
            <mat-icon class="mat-icon-rtl-mirror">
              {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
            </mat-icon>
          </button>
          <mat-checkbox [checked]="descendantsAllSelected(node)"
                        [indeterminate]="descendantsPartiallySelected(node)"
                        (change)="todoItemSelectionToggle(node)">{{getValue(node)}}</mat-checkbox>

        </mat-tree-node>
      </mat-tree>

Answer №1

Customizing default settings for mat-checkbox.

Different options for checkbox click behavior: noop (do not toggle), check (toggle checked only), check-indeterminate (toggle checked and unset indeterminate), and undefined (same as check-indeterminate).

Type definition for checkbox click actions: MatCheckboxClickAction = 'noop' | 'check' | 'check-indeterminate' | undefined;

Use the injection token MAT_CHECKBOX_CLICK_ACTION to specify checkbox click behavior.

const MAT_CHECKBOX_CLICK_ACTION: InjectionToken<MatCheckboxClickAction>;

Implementing this concept may help in resolving the issue you're facing.

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

Encountered an Unhandled Rejection error in React due to SyntaxError: Unexpected token '<' found in JSON at position

Every time I attempt to access the global variable from a different component, specifically when I try to use it from Brewery.js in Random.js, I encounter the "Unhandled Rejection (SyntaxError): Unexpected token < in JSON at position 0" error. Brewery. ...

What is the best way to save the output of an asynchronous (AJAX) function in a variable?

This isn't a repeat query. I'm seeking assistance in locating a technical solution that hasn't been covered in the post How do I return the response from an asynchronous call? If .then() doesn't resolve the Promise, how can I pinpoint ...

I am encountering an issue in Angular where I am trying to add single quotes and a variable to the component.html file

Working with Angular 13, I encountered an issue in my component.html file: The following line functions as expected: <highcharts-chart [constructorType]="'stockChart'"></highcharts-chart> However, when I use a variable: my ...

In TypeScript, when 'this' does not have a specified type annotation, it will implicitly be of type 'any'

I'm facing challenges with redirecting in React using TypeScript. I know it's possible to configure the TS settings to avoid using implicit "this" keyword, but I don't think that's the right approach to truly "fix" it, just a workaround ...

Fixing the issue: "Tricky situation with JavaScript not working within Bootstrap 4's div tag while JS functions properly elsewhere"

Currently, I'm working on implementing a hide/show function for comments using JavaScript. Fortunately, I was able to find a helpful solution here (thanks to "PiggyPlex" for providing the solution on How can I hide/show a div when a button is clicked? ...

Unexpected behavior with jQuery AJAX Callback function:

When attempting to extract data from the success part of an AJAX call, I implemented a callback function for this purpose. Here is the code snippet: var data2; $(function () { function callback(data) { console.log(data); data2 = JSON.parse(data ...

Make a JSONP request with the MIME Type set to text/plain

I've been attempting to utilize JSONP for fetching a feed from a different domain. Despite knowing that the content type should ideally be JSON or JavaScript, it is currently set as text/plain and unfortunately, I lack control over the server settings ...

Angular is getting hung up on the process of "reloading client(s)" and failing to properly refresh the page

As a React developer, I've decided to start learning Angular. I created a new project using "ng new my-first-app", but I'm facing an issue with hot module reload. It stops working shortly after I make changes to the "app-component.html" file and ...

From jQuery to ReactJS: Migrating to a Modern

As I venture into converting existing jQuery code to React.js, I must admit that I am quite new to React and still in the learning phase. So please bear with me if my questions sound a bit silly. Here is the structure I am working with: <ul> &l ...

Unable to activate button click event using jQuery

I am using dot.js to enhance a specific webpage by adding a button that, when clicked, should insert text into a text field and then trigger another button to be clicked as well. To achieve this functionality, I have implemented a click handler for my butt ...

I'm looking to send a response with data using Nest JS API and Postman. How can I accomplish this

As I work on setting up my server using Nest Js, I encountered an issue while trying to fetch data from Postman to test the API urls. Unfortunately, I keep receiving empty responses from the server or undefined values from the postman request. Below is a s ...

What is the best way to reset everything back to its original position by clicking anywhere on the screen except for the specified div?

Is there a way to make the entire screen reset to its original state with just one click anywhere on the screen, rather than having to click a specific button? Any assistance on this matter would be greatly appreciated. Thank you! JQUERY CODE $(".readNow ...

Why do `resolutions` not receive support in package.json like they do in bower.json?

It's common knowledge that resolutions are utilized to address conflicts between packages in the bower.json file. I recently went through the package.json documentation, but couldn't locate any support for the resolutions feature. Could there be ...

Converting Javascript tools into Typescript

I'm currently in the process of migrating my Ionic1 project to Ionic2, and it's been quite an interesting journey so far! One challenge that I'm facing is how to transfer a lengthy list of utility functions written in JavaScript, like CmToFe ...

"Error occurs as a result of an unspecified attribute in the map

Hello, I am currently traversing a tree structure recursively. To handle undefined nodes in the tree, I have implemented guards to prevent any failures. However, during the mapping of children nodes, I encountered the following error: Error Output Adri ...

Activate JavaScript validation

Within each section (displayed as tabs), I have a custom validator. When one tab is active, the other is hidden. To proceed to submission, I need to disable client validation for the inactive tab. I attempt to do this by calling ValidatorEnable(, false); ...

The $scope.$watch function is not triggering events within a controller of a ui.bootstrap.modal

Currently, I am utilizing UI bootstrap for Angular and have successfully integrated the ui.bootstrap.modal component into my project. Everything seems to be working smoothly except for one issue I am encountering. Despite setting up a $scope.$watch to trac ...

Creating glitchy dotted lines in an HTML Canvas with the help of translate and scale techniques

I'm working on creating a canvas where users can draw symmetrical lines with their mouse. However, when I use the transform and scale attributes in the draw function to achieve this effect, it creates small gaps in the line and makes it look less smoo ...

Hide only the table that is being clicked on, not all tables

Essentially, I am using document.querySelectorAll() to retrieve an array of div elements. In my function, handleClick(), each time the button is clicked, I want to hide the table associated with that specific button. This is the current situation: https:/ ...

Despite being logged, the current value of firebase.auth().currentUser in Firebase is null

I have coded a query in my service.TS file that displays the "state" of items based on the UID of the logged-in user: getLists(): FirebaseListObservable<any> { firebase.auth().onAuthStateChanged(function(user) { if (user) {console.log("blah", fir ...