Alert issue

I have a small issue with the basic alert. so here is my scenario.
-> I click the submit button on a page and if no record returned then it will give me a alert message. I click ok to dismiss that. – Works fine.
-> I repeat the same scenario 2nd time by providing invalid input so that i don’t get record back and application gives me same alert again. I click ok to dismiss the alert – Doesn’t work.
Can any on help on this??
Here is my code to fetch the records:

fetchGroupMembers(form) {
    //referring this to obj because scope of this is confusing in callback functions
    var obj = this;
    //creating loader
    let loading = Loading.create({
      content: "Please wait...",
    //Showing loader on current screen
    //Send message to server to fetch the group members
    obj.myGlobals.socket.emit('fetchGroupMembers', { groupCode: form.controls['groupCode'].value });
    obj.myGlobals.socket.on('groupMembers', function (result) {
      while (obj.students.pop()); //removing all elements from array of students
      //fetching each record and creating student
      result.forEach(function (record) {
        obj.students.push(new Student(record));
      //on successfull fetch dismiss the loader
      if (obj.students.length > 0) {
        //set students to global
        obj.myGlobals.students = obj.students
        //navigating to next page with parameters
        obj.nav.push(HostPage, {
          Students: obj.students
      } else {
        //creating alert  

  doAlert() {
    let alert = Alert.create({
      title: 'No Student Found!!',
      subTitle: "Please check group code. can't find students!!",
      buttons: ['OK']
  • If I call the doAlert() on a button click. it works like charm. I can’t figure out the problem why it isn’t working in my scenario.
    Any help would be appreciated.