另一个Component Ionic 4

时间:2019-05-07 16:34:12

标签: angular ionic-framework ionic4

我正在将我的应用程序从Ionic 4迁移到Ionic 3,发现每个组件都使用async and await calls。我知道为什么要使用它,但是在我的Ionic 3应用程序中,Loading Controller Component内有一个嵌套的Alert Controller Component

离子3 .ts

submitAssetLoc(form: NgForm){

    const alert =  this.alertCtrl.create({
       header: 'Submit',
       message: 'Are you sure you want to Submit?',
       buttons: [
         {
           text: 'Yes',
           role: 'Yes',
           handler: () => {
             const loading = this.loadingCtrl.create({
                           message: 'Submitting...'
                          });

          loading.present();

            this.stemAPI.updateGPSLoc(this.testData).subscribe((result) => {

              loading.dismiss();
              
            }, (err) => {
                loading.dismiss();
                let alert = this.alertCtrl.create({

                header: 'Error: Could not submit!',
                message: 'Try submitting again, or submit offline!',
                buttons: [
                  {
                    text: 'Try Submitting Again',
                    role: 'Yes',
                    handler: () => {
                    
                    this.newGPSLoc = [];
                  }
                },
                  {
                    text: 'Submit Offline',
                    handler: () => {
                    
                    this.navCtrl.push(SuccessPage, { 'APIresponse': 'Form submitted offline, please go to support page and re-submit!'});
                    }
                  }
                ]
              });
              alert.present();
            }
         )}
         },
         {
           text: 'No',
           role: 'Cancel',
           handler: () => {

           }
         }
       ]
     });
    alert.present();
  }

我的问题是异步,等待调用未正确实现,我知道 我的代码显然效率不高 。我假设我需要为每种方法制作方法,但是正确实现此功能的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

希望这会有所帮助

<profile_modal>

  <template slot="trigger">

    <figure class="profile-card__figure | image -is1x1">
      <img src="<%= person.avatar.url %>" alt="">
    </figure>
...