2016-08-04 46 views
2

我有一個基本警報小問題。所以這是我的場景。 - >我點擊頁面上的提交按鈕,如果沒有記錄返回,它會給我一個警告消息。我點擊確定,駁回這一點。 - 工作正常。 - >我第二次通過提供無效輸入重複相同的情況,以便我不記錄回來,並且應用程序再次給予我相同的警報。我點擊確定關閉警報 - 不起作用。 任何可以幫助這個? 這裏是我的代碼來獲取記錄:Ionic 2警報問題

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 
    obj.nav.present(loading); 
    //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 
     loading.dismiss(); 
     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 
     }); 
     console.log(obj.nav); 
     } else { 
     //creating alert 
     obj.doAlert(); 
     } 
    }); 

    } 
    doAlert() { 
    let alert = Alert.create({ 
     title: 'No Student Found!!', 
     subTitle: "Please check group code. can't find students!!", 
     buttons: ['OK'] 
    }); 
    this.nav.present(alert); 
    } 
} 

如果我所說的doAlert()點擊一個按鈕。它的作用就像魅力。我無法弄清楚爲什麼它不適用於我的情況。 任何幫助,將不勝感激。 謝謝,

+0

請您創建一個演示plunker所以我們可以看到發生了什麼? – sebaferreras

+0

我真的不知道如何爲分佈式代碼創建plunker(客戶端服務器和服務器再次連接到mLab DB)。 –

+0

似乎我偶然發現了一個類似的問題:第一個彈出工作正常,第二個不能被解僱。提交了一個問題:https://github.com/driftyco/ionic/issues/7554 Plunker在這裏:http://plnkr.co/edit/kC2EtfmONmJ9UxPVXkJE?p=preview @BajinderBudhwar:離子錯誤報告模板有一個方便的鏈接即使您不想提交Ionic錯誤,您也可以使用Ionic Plunker模板。 – Gilead

回答

2

正如Alert類文檔的正確方法是等待由Alert.dismiss(返回的承諾討論)調用來解決:

public TEST =() => { 
    let alert1 : Alert = Alert.create({ 
    title: 'Prompt 1', 
    message: "First", 
    buttons: [{ 
     text : 'OK', 
     handler :() => { 
     console.log("First OK"); 
     alert1.dismiss().then(() => { // wait for the previous transition to finish or the following alert will malfunction 
      let alert2 : Alert = Alert.create({ 
      title : 'Prompt 2', 
      message : "Second", 
      buttons : [{ 
       text : 'OK', 
       handler :() => { 
       console.log("Second OK"); 
       alert2.dismiss(); // DISMISSING MANUALLY 
       } 
      }] 
      }); 
      this.nav.present(alert2); 
     }); 
     } 
    }] 
    }); 
    this.nav.present(alert1); 
}; 
+0

完美的例子..!真的很感謝幫助..謝謝 –

+0

@BajinderBudhwar我很高興它幫助。讚賞和接受的答案,將不勝感激:) – Gilead

+0

不起作用的離子2 ..任何想法?它給了我'未捕獲(承諾):removeView未找到' –