ngModel does not change the Toogle of Ionic 2

0

I have a toogle that enables and disables a function, this already works, what does not work is the state of Toogle in the View, the toogle always stays enabled even with ngmodel = false. code below:

View:

<ion-toggle [(ngModel)]="Ativar" (ionChange)="SimNao()"></ion-toggle>

TS:

SimNao(){
    if(this.Ativar == true){
      this.storage.set('ativar', true);
    }
    if(this.Ativar == false){
      this.storage.set('ativar', false);
    }
  }

Console

console.log(this.Ativar);

Both in the console and in the local storage the values are switched between True and False and in Local Storage everything is working, the function updates the data normally. The only problem is that toogle will always be enabled even if the state is false.

    
asked by anonymous 26.06.2017 / 02:56

1 answer

0

I was able to resolve to get the value of the toogle that was stored in Local Storage, in that code I did not get the value of Toogle, so the solution was to create inside the constructor the code below.

this.storage.get('ativar').then((data) => {
    this.Ativar = data;
});

In this way I pass the correct state of the condition stored in the Bank.

    
05.07.2017 / 23:43