【发布时间】:2018-08-29 14:29:04
【问题描述】:
我正在尝试将所有复选框更改为真或假,使用 1 个复选框,在我的 html 中我得到了更改,但在 console.log();我得到默认值
我正在使用 Ngmodel,但我认为我失败了..
组件.TS
public checkall: boolean = false;
public closures: Array<item>;
HTML->
<div class="toggle-switch">
<input type="checkbox" id="checkAll" name="checkAll" (change)="check()" [(ngModel)]="checkall">
<label for="checkAll"></label>
</div>
<tr *ngFor="let closure of closures">
<input type="checkbox" id="{{closure.id}}" (change) = "check()" name = "{{closure.id}}"[(ngModel)] = "closure.checkclosure"[checked] = "checkall" >
<label for="{{closure.id}}"></label>
check() {
console.log(this.closures);
}
output -> false 但在我的 html 中,我的复选框为 true。
【问题讨论】:
-
闭包中有什么?
-
是的,抱歉,我更新了我的问题。 clousures 是我来自服务器的数组,我将此数组与双数据绑定(“ngModel”)一起使用,因为我知道我的 console.log 中的复选框是正确的
-
问题是我在我的 type="checkbox" id="checkAll" name="checkAll" 中更改,我的 html 更改为 true 但在我的 console.log() 中不是,如果我更改1 通常复选框,我是的 console.log();
标签: angular