【问题标题】:Dismiss loading in Ionic 2关闭 Ionic 2 中的加载
【发布时间】:2017-10-13 00:36:11
【问题描述】:

所以在我的应用程序中,我有一个按钮,单击该按钮会打开 WhatsApp 并发送声音。在这个按钮上,我附加了一个方法,当单击该按钮时,它会创建一个 Ionic 加载组件。我遇到的问题是“loading.dismiss()”。我想让它在启动 WhatsApp 时关闭加载程序。

我曾尝试使用 ionViewWillLeave,但它不起作用,因为 Ionic 无法将打开 WhatsApp 的我的应用识别为“离开”。

soundboard.html(带有点击方式的按钮)

<button ion-button (click)="share(sound.file)"></button>

soundboard.ts

loading = this.loadingCtrl;

public share(file: string): void {
    let loading = this.loadingCtrl.create({
    content: 'Please wait...'
  });
    loading.present();
    SocialSharing.shareViaWhatsAppToReceiver(null, null, file);
    this.turnoff(loading) /* calls the loading.dismiss */
 }

ionViewWillLeave(loading) {
   loading.dismiss();
}

【问题讨论】:

    标签: android angular typescript ionic2


    【解决方案1】:

    根据docs,您的函数返回一个承诺。我会在then 和/或catch 中解散。

      SocialSharing.shareViaWhatsAppToReceiver(null, null, file)
        .then(res=>{
            loading.dismiss();
          }).catch(err=>{
            loading.dismiss();
            console.log(err);
          });
    

    【讨论】:

    【解决方案2】:

    我猜你正在使用 SocialSharing 插件。 https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin 您可以将成功回调传递给 shareViaWhatsAppToReceiver(),并在其中调用 loading.dismiss()。

    从文档中复制:

    <button onclick="window.plugins.socialsharing.shareViaWhatsAppToReceiver(receiver, 'Message via WhatsApp', null /* img */, null /* url */, function() {console.log('share ok')})">msg via WhatsApp for Addressbook ID 101</button>
    

    【讨论】:

    • 如果 OP 直接使用插件,你是对的。虽然这是离子原生包装器。只是说
    猜你喜欢
    • 1970-01-01
    • 2017-07-05
    • 2017-01-03
    • 2023-03-08
    • 2016-08-26
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    相关资源
    最近更新 更多