简体   繁体   中英

Get checkbox value in angular2+ (not using ngModel )

How can I get checkbox value without using ngModel (cause I don't want to declare field variable for every checkbox)

when code be like :

<input type="checkbox" (click)="foo(bar)">

and

public foo(bar) {
    console.log(bar);
}

Expected output is true or false (whatever that shows checkbox status)

<input #bar type="checkbox" (click)="foo(bar.checked)">

演示版

尝试这个

<input type="checkbox" (change)="foo($event.target.checked)">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM