Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
启用/禁用/更改json值的切换按钮_Json_Angular_Toggle - Fatal编程技术网

启用/禁用/更改json值的切换按钮

启用/禁用/更改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

我想创建一个切换按钮,用于更改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 = 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}}

谢谢,效果很好!