question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MdCheckbox does not pass a change event to change handler

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

The component should return a change event like any regular HTML input element does, too. Interestingly, MdInput does return a regular change event.

What is the current behavior?

When binding an event handler via the (change)=“doSomethingOnChange($event)” notation, the MdCheckbox component does not return a DOM change event when checked/unchecked but a custom angular event, which does not bubble like a change event should.

What are the steps to reproduce?

Simply register a change event handler on an <md-checkbox> and log the event.

http://plnkr.co/edit/4KRXLDmbHU2pO7RvBiaw?p=preview

What is the use-case or motivation for changing an existing behavior?

The event should bubble just like a regular HTML checkbox’s events bubble so that container elements can catch their events.

Which versions of Angular, Material, OS, browsers are affected?

I tried both 2.0.2 and 2.3.0

Is there anything else we should know?

A fix would be fantastic. We all appreciate your team’s great work!

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
luminousPearlcommented, Aug 30, 2018

I used both click and change event on mat-checkbox, click for passing the event to stop propagation. The below code worked for me.

<mat-checkbox (change)=“handleProductClick(product)” [checked]=“product.selected” (click)=“$event.stopPropagation()” [id]=“product.id”></mat-checkbox>

2reactions
vidhemacommented, Sep 2, 2017

Here is nice solution via jquery -

`$(‘md-checkbox.toggle-vis’).on( ‘click’, function (e) {

    console.log($(this).find('.mat-checkbox-input').is(":checked"));

});`

just install jquery with npm and put below line in component - `import * as jQuery from ‘jquery’;

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular2 Unit Test - Change event in MdCheckbox is not ...
I can offer you two options: 1) Trigger change event on md-checkbox element it('should call intentChecked on change checkbox', ...
Read more >
onchange Event - W3Schools
The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the...
Read more >
Checkbox | Angular Material
Event emitted when the checkbox's indeterminate value changes. defaultColor: ThemePalette | undefined. Default color to fall back to if no value is set....
Read more >
How To Use React Checkbox onChange Feature (with Code ...
On its own, our Checkbox component has no way to access its parent element, so we have to explicitly pass in the callback...
Read more >
AlertController - Ionic API Documentation
You can pass all of the alert's options in the first argument of the create method: ... If a handler returns false then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found