-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checkbox event.target.checked undefined #1142
Comments
Hm, I was looking at this issue, and it looks like the I think this is an issue which is solvable, but would rather make the components more complex than they need. As a workaround I propose the |
It worked on the eariler version of md-checkbox and the normal |
Definitely, the goal is to make the components as much as consistent to the native ones. It's just a bit more difficult to forward all click events to the underlaying input, because click events can also happen on the label or other container elements inside of the component. Waiting for @jelbourn's opinion on this. |
The workaround with |
@tinayuangao we might need to think a bit about our approach here |
I was having the same issue and using I'll leave my plunkr here: http://plnkr.co/edit/QW2UqY6huRtZVqwfmlbU?p=preview @Component({
selector: 'demo-component',
template: `
Value: {{isChecked}} <br><br>
Native: <input type="checkbox" (click)="doCheck($event)" [checked]="isChecked" /> <br><br>
Click: <md-checkbox (click)="doCheck($event)" [checked]="isChecked"></md-checkbox> <br><br>
Change: <md-checkbox (change)="doCheck($event)" [checked]="isChecked"></md-checkbox>
`
})
export class DemoComponent {
isChecked:boolean = false;
doCheck($event) {
this.isChecked = !this.isChecked;
}
} |
try this
sorry I couldn't get the code formatted correctly. |
hello,
|
Anglar Material-v5 Checkbox provides "MatCheckboxChange" and "checked" properties, using $event (as I did in "ts" |
Closing this since there's a way to get the value presently |
|
try this: ツ
|
Hi, |
How can we get the native event? I have a situation where I want to stop propagation of my event to parent? But I am not able to get that event. |
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
}
} |
Casting to HTMLInputElement works |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
What is the current behavior?
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
The text was updated successfully, but these errors were encountered: