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.

checkbox event.target.checked undefined

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

<md-checkbox (click)="test($event)"></md-checkbox>

test(event) {
  console.log(event.target.checked); // true | false
}

What is the current behavior?

<md-checkbox (click)="test($event)"></md-checkbox>

test(event) {
  console.log(event.target.checked); // undefined
}

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

@angular2-material/checkbox@2.0.0-alpha.7-2 @angular/core@2.0.0-rc.5 @angular/forms@0.3.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
joseluisqcommented, Sep 11, 2018

This works properly for me:

<input type="checkbox" (change)="onChecked($event)">
onChecked (e: Event) {
  const checkbox = e.target as HTMLInputElement;

  if (checkbox.checked) {
    // do something
  }
}
11reactions
mojtaba-ramezanicommented, Mar 9, 2018

try this: ツ

<mat-checkbox (change)="check($event)"></mat-checkbox>
check(event) {
     console.log(event.checked) // true or false
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is '$event.target.checked' giving angular TypeError when ...
When i am trying to use $event.target.checked with angular mat-checkbox its giving an error sating that -"Cannot read property 'checked' of ...
Read more >
How do I read out the value of my checkbox?
Try this: :) var selected = event.target.checked; //true or false.
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 >
Angular 8 Checkbox Change Event Checked undefined
Im trying to execute a function when a checkbox has been ticked/unticked but wasnt able to get the checkbox.checked as it is showing...
Read more >
Checkbox - (React) - Thumbprint Design System
onChange(event.target.checked, props.id, event) . Type. ( value: boolean, id: string | undefined ...
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