2016-04-18 20 views
2

私はこの2つのコンポーネントから、PersonServieで2つのHTTPパラレルリクエストを作成しようとしています。 Observable.forkJoinメソッドは、このエラーがスローされます。しかし:EXCEPTION: TypeError: this._subscribe is not a function in [null]Angular 2 Observable.forkJoin this._subscribeは[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); 
     } 
} 

答えて

9

が間違って使用されているObservable.of(person)の代わりObservable.createを使用してみてください。

+0

ありがとうございますが、問題は解決していません。テストでthis._id> 0に設定しました。私はとにかくその変更をしました。ありがとう – jcmordan

2

私はそれを得ると思います。私が代わりに

diferenceは何ですかimport { Observable } from 'rxjs/Observable';import { Observable } from 'rxjs/Rx'; を輸入したため

問題でしたか?

関連する問題