我一直在开发显示 Facebook 帖子的个人资料页面。但是当我使用浏览器后退/前进按钮返回页面时,不会呈现我的帖子。
- 角 CLI:8.0.1
- 节点:12.14.1
- 操作系统:linux x64
- 角度:8.0.0
profile.component.ts
import { Component, OnInit, OnDestroy, AfterViewInit, AfterContentInit, Renderer2, ElementRef, ViewChild } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { ServerClientService } from '../../shared/serverclient.service';
import { AuthService } from '../../shared/auth.service';
import { FacebookService, InitParams } from 'ngx-facebook';
import { Account } from '../../shared/models/account.model';
declare const $: any;
declare var window: any;
declare var FB: any;
@Component({
selector: 'app-profile',
templateUrl: './profile.component.html'
})
export class ProfileComponent implements OnInit, AfterContentInit {
myAccount: Account;
twitterStatus: Object;
facebookAct: Object;
instagramAct: Object;
youtubeAct: Object;
accountId: string;
isMyself: boolean = false;
profession: string = '';
accountCategoryLabel: string = '';
serverErrorCode: string = '';
@ViewChild('facebook', { static: false }) facebookDiv: ElementRef;
constructor(private serverClient: ServerClientService,
private authService: AuthService,
private router: Router,
private route: ActivatedRoute,
private renderer2: Renderer2,
private el: ElementRef,
private fb: FacebookService) {
let initParams: InitParams = {
xfbml: true,
version: 'v6.0'//v2.8
};
fb.init(initParams);
}
ngOnInit() {
this.serverClient.searchFacebookPosts(this.accountId)
.subscribe(
facebookAct => {
if (facebookAct && facebookAct.posts) {
facebookAct.posts = facebookAct.posts.map(s => {
let ids = s.id.split("_")
s.link = 'https://www.facebook.com/' + ids[0] + '/posts/' + ids[1]
return s;
});
this.facebookAct = facebookAct;
window.FB.XFBML.parse(this.facebookDiv.nativeElement);
console.log("window.FB.XFBML.parse(this.facebookDiv); called.")
}
},
error => {
this.serverErrorCode = error.error.code;
});
}
}
profile.component.html 在我的个人资料页面中,我有以下代码。
<div class="tab-pane" id="facebook">
<app-ifm-fb-post [fbPosts]="facebookAct?.posts"></app-ifm-fb-post>
</div>
该app-ifm-fb-post指令如下。
<div class="row">
<div *ngFor="let fbPost of fbPosts">
<fb-post width=" auto" [href]="fbPost.link"></fb-post>
</div>
</div>
当我运行应用程序时,我可以看到 html 代码。将fb-post使用正确的链接创建并通过https://www.facebook.com/v6.0/plugins/post.php?app_id=&chann(Trimed)仅在浏览器第一次加载时发送和显示帖子来获得帖子。但是当我回到个人资料页面时,我可以fb-post在 html 中看到 s,但https://www.facebook.com/v6.0/plugins/post.php?app_id=&chann(Trimed)不会被调用,也不会显示任何内容。
在浏览器中
<div class="row">
<div class="ng-star-inserted">
<fb-post width=" auto" class="fb-post" data-href="https://www.facebook.com/10217956357636594/posts/10218504599782305" data-width=" auto" ng-reflect-href="https://www.facebook.com/10217" ng-reflect-width=" auto">
</fb-post>
</div>
<div class="ng-star-inserted">
<fb-post width=" auto" class="fb-post" data-href="https://www.facebook.com/10217956357636594/posts/10218501014532676" data-width=" auto" ng-reflect-href="https://www.facebook.com/10217" ng-reflect-width=" auto">
</fb-post>
</div>
</div>
有人可以帮帮我吗!!!?