【发布时间】:2018-06-30 06:36:56
【问题描述】:
我一直在尝试在我的应用中为帖子插入一个分享按钮,该按钮能够使用安装在 android 手机中的默认应用,但似乎无法通过。
这就是我的 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");
});
}
}
问题
如何将帖子标题、网址帖子图片(REST API - JSON)插入this.socialSharing.share("Post Excerpt", "Post Title", "Post Image URL", "Post URL")
让分享按钮看起来更像这样
<button ion-fab class="btn share" mini (click)="sharePost()"></button>
编辑 我已经设法使用
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");
});
}
但是,当我喜欢使用 gmail 分享时,会显示 html 特殊字符
e.g title shows: catering & Cleaning Services
Excerpt shows: <p>Some text[…]</p>
我如何摆脱那些 html 字符,只显示一些干净的文本。?
谢谢
【问题讨论】:
标签: android json wordpress cordova ionic-framework