lundi 22 mai 2017

Checked and unchecked checkbox in Angular 2 by boolean value

I would like to make checkbox in Angular 2 automatically checked or unchecked. When the value is 1 the checkbox will check and this one is 0 the checkbox will automatically uncheck.

public LightControl() {
    this.dataLight = this._LightService.AutoLightController(this._ConnectService.SocketInstanse())
        .subscribe(data => {
            this.temp = JSON.stringify(data['status']);
        })
}

HTML:

 <div class="togglebutton">
    <label> <input type="checkbox" [checked]="temp(change)="temp">Light</label>
 </div>

  • When temp value is true it checked, but when temp is false, it didn't uncheck automatically.



Aucun commentaire:

Enregistrer un commentaire