Angular 8订阅未从服务获取返回数据

Angular 8订阅未从服务获取返回数据,angular,angular2-observables,subscribe,rxjs-observables,Angular,Angular2 Observables,Subscribe,Rxjs Observables,我想在将ID传递给服务并在我的服务器上获取数据后,将数据修补到我的表单,但我没有获取任何数据。这是我的密码 addForm: FormGroup; ngOnInit(){ const routesParams=this.routes.snapshot.params; this.addForm=this.formBuilder.group({ Title:['',[Validators.required,Validators.minLength(1)]],

我想在将ID传递给服务并在我的服务器上获取数据后,将数据修补到我的表单,但我没有获取任何数据。这是我的密码

addForm: FormGroup;
  ngOnInit(){
    const routesParams=this.routes.snapshot.params;


    this.addForm=this.formBuilder.group({
      Title:['',[Validators.required,Validators.minLength(1)]],
      Body:['',[Validators.required,Validators.minLength(1)]],
      Author:['',[Validators.required,Validators.minLength(1)]],
    })
     console.log(routesParams.post_id);

    this.blogService.getBlogbypost_id(routesParams.post_id).subscribe((data:any)=>{
      this.addForm.patchValue(data);

    });
  }
我的服务代码.ts


我也在服务器上获取数据,但不在SubscribedData上获取数据:any

Hi更改代码,如下所述:

    getBlogbypost_id(id:number): Observable<cBlog[]>{
      return this.http.get<cBlog[]>(this.updateUrl+id);
    }



 this.blogService.getBlogbypost_id(routesParams.post_id)().subscribe((data:any)=>{
      console.log(data);
      this.addForm.patchValue(data);
    });

让我知道结果是什么

尝试以这种方式修补价值-我不知道您的数据结构是什么样子,然后我在途中写了这篇文章,但您会得到它-看一看:

this.blogService.getBlogbypost_id(routesParams.post_id).subscribe((data:any)=>{
    this.addForm.patchValue({
        Title: data.title,
        Body: data.body,
        Author: data.author
    });
});
patchValue并不能真正捕获嵌套错误,正如文档所述,有时您无法知道发生了什么


希望这会有帮助

您应该使用resolver.console.logthis.updateUrl+id并检查您正在访问正确的URL,并确保返回类型很高兴听到这个消息
this.blogService.getBlogbypost_id(routesParams.post_id).subscribe((data:any)=>{
    this.addForm.patchValue({
        Title: data.title,
        Body: data.body,
        Author: data.author
    });
});