我有一个Web应用程序。在我的右侧栏中,我有3个帖子。 当我点击后,我有一个导航:角ngOnInit - 刷新所需
this.router.navigate(['../post', this.post.id]);
有一个后档组件将接管。 此组件具有一个函数,该函数可以从使用指定标识获取我的帖子的服务调用函数。现在,我将在我的内容区域(屏幕的左侧部分)中看到该帖子的所有详细信息。该函数(获取我的文章)仅在Post Profile组件的ngOnInit中调用。
如果我从我的右边栏另一篇文章点击,我可以看到URL的变化但得到我的职位是不是叫和我的内容区域的细节后不改变功能。 如果我现在刷新页面,我可以看到我想要的帖子,一切正常。
我有我的功能.subscribe,有没有什么帮助。
我看不到的问题。
这是我PostProfileComponent
constructor(postsService: PostsService, route: ActivatedRoute) {
this.postsService = postsService;
this.routeSubscription = route.params
.subscribe((params: any) => {
this.postId = params['id'];
});
}
public getPostById(id: any): void {
this.postsService.getPostById(id)
.map((response: Post) => {
this.post = response;
console.log(this.post);
})
.catch((error: any) => {
return error;
})
.subscribe();
}
ngOnInit(): void {
this.getPostById(this.postId);
}
你真的必须展示你的实际代码,没有人能猜到你的代码是怎样的。 [如何创建一个最小,完整和可验证的示例](https://stackoverflow.com/help/mcve) – Alex