How to refresh current page after click/handling 'Ok' Alert!


#1

Currently what I’m doing is pop() the page so the user enters again in order to load the changes, but that’s not how it should be
this is the code:

addCourse(param){

let alert = this.alertCtrl.create({
  title: 'Add course',
  buttons: [
    'Cancel'
  ]
});
alert.addInput({
  name: 'param',
  placeholder: 'course name'
});
alert.addButton({
  text: 'Add',
  handler: data => {
    this.schoolAppUsers.insertStudentCourse(this.UserID, data.param).subscribe(res => {
      let alert = this.alertCtrl.create({
        message: res[0].message,
        buttons: [{
          text: 'Ok',
          handler: () =>{
            let navTransition = alert.dismiss();
            navTransition.then(() => {
              this.navCtrl.pop();
            });
            return false;
          }
        }]
      });
      alert.present();
    })
  }
});
alert.present();
}

The page has list of courses , so when every time the admin adds a course , it should refresh the page to show the new changes rather than pop() !!


#2

Generally the data model is stored in an injectable service, so when the course is added, it will automatically be picked up by change detection.


#3

I don’t understand what you mean by data model ! This code is in a component (page) , are you saying that what ever is listing the items , should be stored in a global service , by set and get ???


#4

Yes, that makes your problem go away naturally. You don’t have to think in terms of “refreshing the page” - if the data is stored in a shared service, it can be updated from anywhere.


#5

Mr. rapropos , can you check this issue