Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 为什么订阅无法读取api响应_Angular - Fatal编程技术网

Angular 为什么订阅无法读取api响应

Angular 为什么订阅无法读取api响应,angular,Angular,我正在尝试使用一种方法,该方法使用其id号为我提供用户信息 组件技术 identificacion:any = this.route.snapshot.paramMap.get('identificacion'); constructor(private route: ActivatedRoute, private dataService: DataService) { } async ngOnInit() { await this.dataService.getP

我正在尝试使用一种方法,该方法使用其id号为我提供用户信息

组件技术

identificacion:any = this.route.snapshot.paramMap.get('identificacion');
  
  constructor(private route: ActivatedRoute, private dataService: DataService) { 
  }

  async ngOnInit() {
    await this.dataService.getParticipeByIdentificacion(this.identificacion).subscribe(resonse => console.log(resonse))
    }
服务电话:

getParticipeByIdentificacion(id) {
    this.tokenvalido();
    const token = this.getToken();
    return this.http.get(`${this.apiUrl}/participe/identificacion/${id}`);
  }
api的回应:

{
  "result": {
    "actividadEconomica": null,
    "genero": "Masculino",
    "estadoCivil": "SOLTERO",
    "contratos": [],
    "contactos": [],
    "direcciones": [],
    "referenciasPersonales": [],
    "referenciasBancarias": [],
    "idParticipe": 195,
    "idTipoIdentificacion": 1,
    "tipoIdentificacion": null,
    "identificacion": null,
    "nombres": "WILMER JAVIER",
    "apellidos": "DECIMAVILLA ESPINOZA",
    "razonSocial": "WILMER JAVIER DECIMAVILLA ESPINOZA",
    "fechaRegistro": "2021-02-08T19:57:30.277",
    "fechaModificacion": "2021-05-12T11:39:31.413",
    "usuarioRegistro": "SYSTEM",
    "usuarioModificacion": "",
    "estado": "Aprobado",
    "fechaNacimiento": "",
    "lugarNacimiento": "N/A",
    "idNacionalidad": 1,
    "fechaExpedicionCedula": "0001-01-01T00:00:00",
    "correo1": null,
    "correo2": null,
    "telefono1": null,
    "telefono2": null,
    "celular": null,
    "idGenero": 1,
    "idEstadoCivil": 1,
    "idNivelEstudios": 3,
    "idNivelIngresos": 2,
    "idProfesion": 1,
    "idGrado": 102,
    "identificacionConyuge": null,
    "conyuge": null,
    "idTipoVivienda": 1,
    "tiempoResidencia": 1,
    "photoUrl": null,
    "codigoUniformado": null,
    "fechaIngreso": "2010-10-21T00:00:00",
    "aporteAdicional": 0,
    "observaciones": null
  },
  "error": null,
  "message": "El servidor respondio con el codigo de estado: 200 OK",
  "statusCode": "OK",
  "success": true
}
我得到的错误是:

ERROR TypeError:您在需要流的位置提供了“undefined”。您可以提供一个可观察的、承诺的、数组的或可观察的


希望你们能帮助我:)

你可以避免异步ngOnInit,只使用带有
isLoad
标志的可观察对象

标识:任意;
isLoad:布尔值;
订阅=新订阅
构造函数(私有路由:ActivatedRoute,私有数据服务:数据服务){
}
恩戈尼尼特(){
this.identification=this.route.snapshot.paramMap.get('identification');
const stream=this.dataService.getparticipebyIdentification(this.Identification).pipe(
轻触((分辨率)=>console.log(分辨率))
.subscribe(()=>this.isLoad=true)
this.subscription.add(流)
}
恩贡德斯特罗(){
this.subscriptions.unsubscribe()//记住取消订阅
}
然后,只有当您有数据时,才可以使用您的标志来呈现页面


//这里是您的数据加载

rxjs和observable功能非常强大。我避免了所有的异步等待,只在我的应用程序中使用它们,我对此很感兴趣!

我怀疑错误与您发布的代码有关。此外,您不能等待observable(或订阅)。。