ngIf显示按钮

时间:2018-02-10 05:24:30

标签: angular ionic-framework ionic2 ionic3

我希望根据localstorage是否等于其值(完整)来显示一个按钮。我的localstorage.setItem(' Level1','完成') 。出于某种原因,* ngIf不起作用,我不知道为什么......

ts文件

Level1: string;

constructor(){}

  ionViewDidLoad() {
    let Level1 = localStorage.getItem('Level1');
  }

HTML

      <div *ngIf="Level1 !== complete">
  <button clear class="button12" id="button1" ion-button color="stable" block large style="color:#000000;" (click)="openModal()">
    Player Button
  </button>
</div>

<div *ngIf="Level1 === complete">
<button clear class="button12complete" id="button2" ion-button color="stable" block large style="color:#000000;" (click)="openModal()">
    <!--<ion-icon name="american-football"></ion-icon> -->
    Player Button
  </button>
</div>

2 个答案:

答案 0 :(得分:2)

试试这个

*ngIf="Level1 !== 'complete'"
export class HomePage {
  Level1;
  constructor(public navCtrl: NavController) {

  }
  ionViewDidLoad() {
    this.Level1 = 'complete';//localStorage.getItem('Level1');
  }

}

<强> WORKING DEMO

答案 1 :(得分:1)

修改

ionViewDidLoad() {
    let Level1 = localStorage.getItem('Level1');
  }

ionViewDidLoad() {
this.Level1 = localStorage.getItem('Level1');


}

更新::同时注入依赖项