Angular 前后端交互时展开对应数据详细信息获取不到对应ID

例子:
ngOnInit() {
this.activatedRoute.queryParams.pipe(map(params => this.loanProductsId = 
params['loanProductsId']), mergeMap(() => {
  console.log(this.loanProductsId);
  return this.udpService.getUdp(this.loanProductsId).pipe(map(value => {
    const resp = value as GeneralResponse;
    if ('0' === resp.code) {
      this.udpEntity = resp.data;
    } else {
      this.messageService.add({severity: 'error', detail: resp.message});
    }
  }));
}));}

注意:如果前端对应传值id没获取到在浏览器输出打印数据查看是否获取到值

比如:console.log(this.loanProductsId);

修改:

ngOnInit() {

this.activatedRoute.queryParams.pipe(map(params => this.loanProductsId = params['loanProductsId']), mergeMap(() => {

    if (this.loanProductsId) {
      return this.udpService.getUdp(this.loanProductsId);
    } else {
      return of({code: '0', data: this.udpEntity});
    }

  })).subscribe(value => {
    const resp = value as GeneralResponse;
    if ('0' === resp.code) {
      this.udpEntity = resp.data;
    } else {
      this.messageService.add({severity: 'error', detail: resp.message});
    }
  });
}

html获取值对应例子:

<div class="p-col-2">
  产品ID:
</div>
<div class="p-col-4">
  <input type="text" pInputText [(ngModel)]="udpEntity.loanProductsId"/>
</div>

版权声明:本文为qq_45866386原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。