gpt4 book ai didi

Angular 2 Observable.forkJoin this._subscribe 不是 [null] 中的函数

转载 作者:行者123 更新时间:2023-12-02 12:55:49 25 4
gpt4 key购买 nike

我有这个 Angular2 组件,我尝试使用 PersonServie 发出两个 HTTP 并行请求(效果很好)。但是 Observable.forkJoin 方法会抛出此错误:EXCEPTION: TypeError: this._subscribe is not a function in [null]

评估 getIdentificationTypes()getPerson() 函数,每个函数返回一个 Observable 对象。

我错过了什么?

 import { Component, OnInit } from 'angular2/core';
import { Router, RouteParams } from 'angular2/router';
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';
import { Observable } from 'rxjs/Rx';
import 'rxjs/Rx';

// more imports for models and other components//


@Component({
selector: 'my-coponent',
templateUrl: 'template',
directives: [ROUTER_DIRECTIVES]
})

export class MyComponent implements OnInit {
public identificationTypes: IdentificationType[];
public person : Person;
// some public and private properties here //

constructor(
private _router: Router,
private _routeParams : RouteParams,
private _personService: PersonServie
){}

ngOnInit() {
let id= (this._routeParams.get('id'));
this._id= id? +id: 0;

Observable.forkJoin([
this.getIdentificationTypes(),
this.getPerson(this._id)
]).subscribe(data =>{
this.identificationTypes= data[0];
this.person= data[1];
});
}

private getIdentificationTypes(){
return this._generalService.getIdentifiacitonTypes();
}

private getPerson(person: number){
if(athleteId == 0){
let person = new Person();
return Observable.create(person );
}


return this._personService.getPerson(athleteId);
}
}

最佳答案

尝试使用 Observable.of(person) 而不是错误使用的 Observable.create

关于Angular 2 Observable.forkJoin this._subscribe 不是 [null] 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36706198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com