jcm*_*dan 2 observable angular
我有这个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);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3294 次 |
最近记录: |