简体   繁体   English

如何将社交共享添加到发布Ionic Wordpress应用程序

[英]How to add Social share to a post Ionic wordpress app

I have been trying to insert a share button for a post in my app that is able to use the default apps installed in the android phone and can not seem to find a way through. 我一直在尝试在我的应用程序中插入帖子的共享按钮,该按钮能够使用android手机中安装的默认应用程序,并且似乎找不到解决方法。

This is how my post.ts file looks like 这就是我的post.ts文件的样子

import { Component } from '@angular/core';
import { NavParams, NavController, AlertController } from 'ionic-angular';
.
.
import { SocialSharing } from '@ionic-native/social-sharing';


/**
 * Generated class for the PostPage page.
 */


@Component({
  selector: 'page-post',
  templateUrl: 'post.html'
})
export class PostPage {

  post: any;
  user: string; 
  comments: Array<any> = new Array<any>();
  categories: Array<any> = new Array<any>();
  morePagesAvailable: boolean = true;

  constructor(
    public navParams: NavParams,
    public navCtrl: NavController,
    public alertCtrl: AlertController,
    private socialSharing: SocialSharing
  ) {

  }

  ionViewWillEnter(){
    this.morePagesAvailable = true;

    this.post = this.navParams.get('item');

    Observable.forkJoin(
      this.getAuthorData(),
      this.getCategories(),
      this.getComments())
      .subscribe(data => {
        this.user = data[0].name;
        this.categories = data[1];
        this.comments = data[2];
      });
  }

  getAuthorData(){
    return this.wordpressService.getAuthor(this.post.author);
  }

  getCategories(){
    return this.wordpressService.getPostCategories(this.post);
  }

  getComments(){
    return this.wordpressService.getComments(this.post.id);
  }

  loadMoreComments(infiniteScroll) {
    let page = (this.comments.length/10) + 1;
    this.wordpressService.getComments(this.post.id, page)
    .subscribe(data => {
      for(let item of data){
        this.comments.push(item);
      }
      infiniteScroll.complete();
    }, err => {
      console.log(err);
      this.morePagesAvailable = false;
    })
  }

  goToCategoryPosts(categoryId, categoryTitle){
    this.navCtrl.push(HomePage, {
      id: categoryId,
      title: categoryTitle
    })
  }


// Social sharing function is here

 sharePost() {

    this.socialSharing.share("Post Excerpt", "Post Title", "Post Image URL", "Post URL")
    .then(() => {
      console.log("sharePost: Success");
    }).catch(() => {
      console.error("sharePost: failed");
    });

  }

}

Problem How do insert the post title, post url post image (REST API - JSON) into this.socialSharing.share("Post Excerpt", "Post Title", "Post Image URL", "Post URL") so that the share button can look more like this 问题如何插入帖子标题,将URL帖子图像(REST API-JSON)插入this.socialSharing.share("Post Excerpt", "Post Title", "Post Image URL", "Post URL")以便共享按钮可以看起来像这样

<button ion-fab class="btn share" mini (click)="sharePost()">&#xF497;</button>

EDIT I have managed to make it work using 编辑我设法使其使用

sharePost() {

    this.socialSharing.share(this.post.excerpt.rendered, this.post.title.rendered, this.post.images.large, this.post.link)
    .then(() => {
      console.log("sharePost: Success");
    }).catch(() => {
      console.error("sharePost: failed");
    });

  }

However when i share like using gmail, the html special characters display 但是,当我共享使用gmail之类的内容时,会显示html特殊字符

e.g title shows: catering &#038; Cleaning Services 
Excerpt shows:   <p>Some text[&hellip;]</p>

How do i get rid of those html characters and just show some clean text.? 我如何摆脱那些html字符,而只显示一些干净的文本。

Thank you 谢谢

One way i removed html tag from my wordpress post was to create a pipe and i pass the excerpt through the pipe before it gets rendered to the view 我从wordpress帖子中删除html标签的一种方法是创建一个管道,然后在将其呈现给视图之前,将摘录通过管道

Pipe.ts was like so Pipe.ts就像这样

import { Pipe, PipeTransform } from '@angular/core';

/**
 * Generated class for the RemovehtmltagsPipe pipe.
 *
 * See https://angular.io/api/core/Pipe for more info on Angular Pipes.
 */
@Pipe({
  name: 'RemovehtmltagsPipe',
})
export class RemovehtmltagsPipe implements PipeTransform {
  /**
   * Takes a value and makes it lowercase.
   */
  transform(value: string) {
    if (value) {
      let result = value.replace(/<\/?[^>]+>/gi, "");
      return result;
    }
    else {

    }
  }
}

Then i added the pipe as export in my component's module.ts 然后我将管道作为导出添加到组件的module.ts中

details.module.ts was like so details.module.ts就像这样

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 
import { IonicPageModule } from 'ionic-angular';
import { DetailsPage } from './details';
import { RemovehtmltagsPipe } from 
'../../pipes/removehtmltags/removehtmltags';

@NgModule({
  declarations: [
    DetailsPage,
  ],
  imports: [
    IonicPageModule.forChild(DetailsPage),
  ],
  exports: [RemovehtmltagsPipe],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class DetailsPageModule {}

Finally used the pipe inside my html code 终于在我的html代码中使用了管道

details.html details.html

 <ion-row class="white-bg" padding>
    <ion-col>
        <h1 class="title">{{article.title.rendered | RemovehtmltagsPipe}}</h1>
        <p class="date">Published: {{article.modified.split('T')[0]}}  {{article.modified.split('T')[1]}}</p>
    </ion-col>
</ion-row>

This should get rid of any html tags in your post.Hope this helps 这应该摆脱您帖子中的任何html标签。希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ionic 2 Native Social Share错误 - Ionic 2 Native Social Share error 如何在android scringo社交网络应用中为帖子和消息添加铃声或振动通知? - how to add ringtone or vibrate notifications for post and messages in android scringo social networking app? Ionic:通过社交媒体分享特定页面 - Ionic: Share specific page via social media 如何通过离子应用程序在whatsapp上共享图像 - how to share images on whatsapp through ionic app 如何在 Android 应用程序中将视频 (.mp4) 分享到社交媒体? - How to share video (.mp4) to social media in Android App? 添加“分享”按钮以在社交网络上分享应用 - Adding a "share" button to share the app on social networks 如何在离子应用程序中共享链接回该应用程序的链接 - How to share a link within ionic app that links back to the app 如何将图像从外部应用程序共享到 Ionic 4 应用程序 - How to share an image from external app to an Ionic 4 app 将社交共享链接添加到phonegap应用 - adding social share links to phonegap app 如何通过Instagram,Whatsapp或任何社交应用程序从自己的应用程序共享图像文件? - How to share the image file from your own app through Instagram, Whatsapp or maybe any social app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM