.then错误(类型“ void”不存在属性“ then”。)

时间:2020-03-05 07:52:43

标签: ionic-framework

我刚接触离子角膜,请帮忙。

this.socialSharing.shareViaInstagram('test test', newBase64).then((res) => {
  console.log("testvalue=====", res);
}).catch((error) => {
  console.log("error value ====", error);
});

4 个答案:

答案 0 :(得分:0)

那是因为它没有返回Promise。

shareViaInstagram: (message?: string, fileOrFileArray?: string | ArrayLike<string>, successCallback?: SocialSharingSuccessCallback<never>, errorCallback?: SocialSharingErrorCallback) => void

请参阅https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/blob/091df268b17b6092cb4224ff9bc65f87b2e3419d/types/index.d.ts#L34

您需要改为:

const onSuccess = () => console.log("testvalue=====", res);
const onError = (error) => console.log("error value ====", error);

this.socialSharing.shareViaInstagram('test test', newBase64, onSuccess, onError);

答案 1 :(得分:0)

只需将then更改为subscribe

this.socialSharing.shareViaInstagram('test test', newBase64).subscribe(res => {
      console.log("testvalue=====", res);
} ,error => {
      console.log(error);
};

答案 2 :(得分:0)

从'@ ionic-native / social-sharing'导入{SocialSharing};

导入

您没有正确导入软件包。最后添加ngx

import { SocialSharing } from '@ionic-native/social-sharing/ngx';


分享到Instagram功能

直接分享到Instagram

shareViaInstagram(message: string, image: string): Promise<any> {
  return;
}

或通过应用名称共享

shareVia(
    appName: string, // <-- instagram
    message: string,
    subject?: string,
    image?: string,
    url?: string
  ): Promise<any> {
    return;
  }

您还可以检查是否可以共享到Instagram,请在提供的文档中查找该功能。

文档:
https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/social-sharing/index.ts

答案 3 :(得分:0)

检查是否已导入模块

就我而言:

import { SocialSharing } from '@ionic-native/social-sharing/ngx'