启用/禁用/更改json值的切换按钮
我想创建一个切换按钮,用于更改Dom中的json布尔值。我想禁用或启用div启用/禁用/更改json值的切换按钮,json,angular,toggle,Json,Angular,Toggle,我想创建一个切换按钮,用于更改Dom中的json布尔值。我想禁用或启用div check:boolean=true; 检查状态(状态){ 如果(状态){ 此项检查=错误; }否则{ this.check=true; } 控制台日志(状态); } { id:1, 名称:“光伏板”, 电流P:'100千瓦', setpp:“100千瓦”, currentq:'2 kVar', setq:‘2千伏安’, 必填项:true }, HTML 试试这个: TS文件 check: boolean = fa
check:boolean=true;
检查状态(状态){
如果(状态){
此项检查=错误;
}否则{
this.check=true;
}
控制台日志(状态);
}
{
id:1,
名称:“光伏板”,
电流P:'100千瓦',
setpp:“100千瓦”,
currentq:'2 kVar',
setq:‘2千伏安’,
必填项:true
},
HTML
试试这个:
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 }}
显示或隐藏的DIV
{{this.json | json}}
谢谢,效果很好!