-1

import { Component, OnInit } from '@angular/core';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';

@Component({
  selector: 'app-video',
  templateUrl: './video.page.html',
  styleUrls: ['./video.page.scss'],
})
export class VideoPage implements OnInit {

  constructor(private socialSharing: SocialSharing) { }

  ngOnInit() {
  }

}

this.socialSharing.shareViaWhatsApp(Text, Image, URL).then((res) => {
  // Success
}).catch((e) => {
  // Error!
});

this.socialSharing.shareViaFacebook(Text, Image, URL).then((res) => {
  // Success
}).catch((e) => {
  // Error!
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

控制台日志时收到错误消息:无法在模块的webpack_require (bootstrap:84) 处读取模块../src/app/video/video.page.ts (video.page.ts:19) 处未定义的属性“socialSharing” 。 ./src/app/video/video-routing.module.ts (video-video-module.js:27)

已遵循以下说明: https ://enappd-apps.gitbook.io/apps/ionic-4-full-app/pro-pack-features/social-logins

4

2 回答 2

1

试试这个代码:

import { Component, OnInit } from '@angular/core';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';

@Component({
  selector: 'app-video',
  templateUrl: './video.page.html',
  styleUrls: ['./video.page.scss'],
})
export class VideoPage implements OnInit {

  constructor(private socialSharing: SocialSharing) { }

  ngOnInit() {
  }

    this.socialSharing.shareViaWhatsApp(Text, Image, URL).then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });

    this.socialSharing.shareViaFacebook(Text, Image, URL).then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });
}

您应该将所有功能放在组件类中。

于 2019-12-11T05:12:47.930 回答
0

感谢您的回复,但它并没有真正起作用。收到错误消息(见截图)在此处输入图像描述

import { Component, OnInit } from '@angular/core';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';

import { url } from 'inspector';
import { Subject } from 'rxjs/internal/Subject';

@Component({
  selector: 'app-video',
  templateUrl: './video.page.html',
  styleUrls: ['./video.page.scss'],
})
export class VideoPage implements OnInit {

  constructor(private socialSharing: SocialSharing) { }

  ngOnInit() {


this.socialSharing.shareViaWhatsApp(Text, Image, URL).then((res) => {
    // Success
  }).catch((e) => {
    // Error!
  });

this.socialSharing.shareViaInstagram(Text, Image).then((res) => {
    // Success
  }).catch((e) => {
    // Error!
  });


this.socialSharing.shareViaFacebook(Text, Image, URL).then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });

this.socialSharing.shareViaTwitter(Text, Image, url).then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });

this.socialSharing.canShareViaEmail().then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });

this.socialSharing.shareViaEmail(Body, Subject, ['recipient@example.org']).then((res) => {
      // Success
    }).catch((e) => {
      // Error!
    });

  }
}

![{ "resource": "/c:/Users/Owner/ionic4-background-video-app/src/app/video/video.page.ts", "owner": "typescript", "code": " 2693", "severity": 8, "message": "'Body' 仅指一种类型,但在这里用作值。", "source": "ts", "startLineNumber": 50, "startColumn ": 34, "endLineNumber": 50, "endColumn": 38 }] 1

于 2019-12-11T13:00:48.503 回答