我正在尝试获取单个帖子的详细信息,但似乎它返回的是所有帖子的数组,而不是单击的帖子,
Post service
export class PostsService {
apiUrl = 'https://example.com/api/posts/';
constructor(private http: HttpClient) { }
getPosts(): Observable<any> {
return this.http.get(`${this.apiUrl}`).pipe(
map(posts => posts)
);
}
//getting single post
getDetails(url) {
return this.http.get(`${this.apiUrl}?i=${url}&plot=full`);
}
}
post detail controller
export class PostsDetailsPage implements OnInit {
post: any;
constructor(private activatedRoute: ActivatedRoute, private postsService: PostsService) { }
ngOnInit() {
let url = this.activatedRoute.snapshot.paramMap.get('url');
this.postsService.getDetails(url).subscribe(res => {
this.post = res;
console.log(res); //see next part
});
}
}
console.log(res); returns
(73) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
res
在我的帖子控制器中应该返回单个帖子详细信息,但其行为与我的博客页面相同(返回所有帖子)。
routes
{ path: 'posts', loadChildren: './pages/posts/posts.module#PostsPageModule' },
{ path: 'posts/:url', loadChildren: './pages/posts-details/posts-details.module#PostsDetailsPageModule' },
有什么主意吗?
如您所见,我的后端工作正常,问题出在我的前端功能(上面共享)
答案 0 :(得分:2)
问题是由我的获取网址引起的,我将其更改为下面的代码,现在可以正常工作了,
getDetails(url) {
return this.http.get(`${this.apiUrl}${url}`).pipe(
map(post => post)
);
}
我从获得零件中删除了?i=
和&plot=full
。
答案 1 :(得分:0)
在我看来,您的url参数未定义。您是否在devtools中检查了网络标签?在那里,您可以准确地看到已将哪些呼叫发送到服务器。否则,我建议对获取它的地方进行一些重构:
RuleException:
CalledProcessError in line 17 of /data/data/Samples/snakemake-example/WGS-test/step2.smk:
Command ' set -euo pipefail; bwa mem -M -t 8 /data/data/reference/refs/ucsc.hg19.fasta.gz raw/sub1_1.fastq.gz raw/sub1_2.fastq.gz raw/sub2_1.fastq.gz raw/sub2_2.fastq.gz raw/sub1_1.fastq.gz raw/sub1_2.fastq.gz raw/sub2_1.fastq.gz raw/sub2_2.fastq.gz raw/sub1_1.fastq.gz raw/sub1_2.fastq.gz raw/sub2_1.fastq.gz raw/sub2_2.fastq.gz raw/sub1_1.fastq.gz raw/sub1_2.fastq.gz raw/sub2_1.fastq.gz raw/sub2_2.fastq.gz | samtools view -Sbh - > raw/sub2.bam ' returned non-zero exit status 1.
File "/data/data/Samples/snakemake-example/WGS-test/step2.smk", line 17, in __rule_bwa_map
File "/root/miniconda3/envs/bioinfo/lib/python3.6/concurrent/futures/thread.py", line 56, in run
访问ActivatedRoute时,您不应该需要快照。另外,我宁愿使用params.subscribe而不是paramMap,因为