离子3:未被发现(在承诺中):找不到删除视图



我在我的页面上调用警报。

addError(title,message){
    const alert = this.alertCtrl.create({
        'title': title,
        'subTitle': message,
        'buttons': ['OK']
    });
    alert.present();
  }

html代码,内容包括按钮和文本框。

<ion-content padding>
 <ion-list>
    <ion-item>
      <ion-label fixed>Name</ion-label>
      <ion-input type="text" [(ngModel)]="name"></ion-input>
    </ion-item>
    <ion-item>
      <ion-label fixed>Secret</ion-label>
      <ion-input type="text" [(ngModel)]="secret"></ion-input>
    </ion-item>
  </ion-list>
  <div padding>
    <button ion-button color="primary" (click)="add();" block>Add New</button>
  </div>
</ion-content>

下面给出了整个.ts代码

class HomePage {
  name:string;
  secret:string;
  constructor(public navCtrl: NavController,public alertCtrl: AlertController,public strorage:StorageServiceProvider) {
  }
  addError(title,message){
    const alert = this.alertCtrl.create({
        'title': title,
        'subTitle': message,
        'buttons': [{
                text: "Cancel", handler: () => {
                  alert.dismiss(); 
                  return false;
                }
              }]
    });
    alert.present();
  }
  add(){
    if(this.name && this.secret){
        this.strorage.addNew({'name':this.name,'secret':this.secret});
    }
    else{
        this.addError("Error","Please enter Secret name and Secret");
    }
  }
}

我再次调用Adderror时会遇到以下错误。

未被发现(在承诺中):找不到删除视图

问题不是来自addError功能和alertController

问题可能是由于本地存储使用this.strorage.addNew({'name':this.name,'secret':this.secret});

而发生的。

此局部存储使用必须像

this.storage.addNew( key, value )  
this.storage.addNew( 'error', {'name':this.name,'secret':this.secret} )

在您的代码中没有钥匙!..

最新更新