3

I am calling an alert on my Page.

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

Html Code with content including button and textbox.

<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>

The Entire .ts code is given below with class definition

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");
    }
  }
}

I am getting the following error while I am calling the addError again.

Uncaught (in promise): removeView was not found

Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41

1 Answers1

0

The problem is not coming from addError function and alertController.

The problem may occurs because of local storage usage this.strorage.addNew({'name':this.name,'secret':this.secret});

This localStorage usage must be as like

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

In your code there is no key !..

Dr. X
  • 2,890
  • 2
  • 15
  • 37
  • If u use official ionic local storage this usage will be as `this.storage.set(key, value)` – Dr. X Oct 01 '17 at 06:49
  • strorage:StorageServiceProvider is my custom service and addNew accept a type any. – Mantu Nigam Oct 01 '17 at 12:36
  • I can say that your alert works well because I tried....This problem is not related about alert component... please run `ionic info` and send add the details to your question – Dr. X Oct 01 '17 at 17:03