我想创建一个切换按钮,用于更改Dom中的json布尔值。我想禁用或启用div
check: boolean = true;
checkStatus(status) {
if(status) {
this.check = false;
} else {
this.check = true;
}
console.log(status);
}
{
id: 1,
name: 'PV Panels',
currentP: '100 kW',
setpp: '100 kW',
currentq: '2 kVar',
setq: '2 kVar',
required: true
},
HTML
<label>
<td ><input [ngModel]="test" [checked]="check" type="checkbox" (change) = "checkStatus(status)"></td>
</label>
答案 0 :(得分:0)
尝试一下:
https://stackblitz.com/edit/angular-5xyuaq?file=src%2Fapp%2Fapp.component.ts
TS文件
check: boolean = false;
checkStatus() {
this.check = !this.check;
this.json.required = this.check;
}
json = {
id: 1,
name: 'PV Panels',
currentP: '100 kW',
setpp: '100 kW',
currentq: '2 kVar',
setq: '2 kVar',
required: this.check
}
HTML文件
<label>
<td >
<input [checked]="this.check"
type="checkbox" (change) = "this.checkStatus()">
</td>
</label>
<div *ngIf="check">
DIV TO SHOW OR HIDE
</div>
{{ this.json | json }}