2016-10-16 13 views
1

角度2.rc.4とrxjs.beta.6から角度2のfinalとrxjs.beta.12にアップグレードして以来、もうエラーメッセージが表示されず、チェンジログに何も見つかりません。問題のあるコードにいくつかのコメントを挿入しました。このすべてがrc.4角度2.rc4から最終的な角度への角度更新後に観測できないことがわかりました

サービス

import { Injectable } from '@angular/core'; 
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; 

import { ApiService } from './api.service'; 

@Injectable() 
export class StocksService { 

    private _portfolio: BehaviorSubject<any>; 
    private _transactions: BehaviorSubject<any>; 

    constructor(private apiService: ApiService) { 
    this._portfolio = BehaviorSubject.create(); 
    } 

    get portfolio() { 
    return this._portfolio.asObservable(); 
    } 

    get transactions() { 
    return this._transactions.asObservable(); 
    } 

    loadPortfolio(): void { 
    this.apiService.get('/depot') 
    .map(res => res.json()) 
// the correct data is in res.data here, but it doesn't get to the component 
    .subscribe(res => this._portfolio.next(res.data)); 
    } 

    loadTransactions(): void { 
    this.apiService.get('/transactions') 
    .map(res => res.json()) 
    .subscribe(res => this._transactions.next(res.data)); 
    } 

    search(id: string) { 
    return this.apiService.get('/stocks/search') 
    .map(res => res.json()); 
    } 

} 

とコンポーネント

import { Component, OnInit } from '@angular/core'; 
import { Observable } from 'rxjs/Observable'; 

import { StocksService } from './stocks.service'; 

@Component({ 
    selector: 'tradity-portfolio', 
    templateUrl: 'app/portfolio.component.html', 
    providers: [StocksService] 
}) 
export class PortfolioComponent implements OnInit { 

    portfolio: Observable<any>; 

    constructor(private stocksService: StocksService) { } 

    ngOnInit() { 
    this.portfolio = this.stocksService.portfolio; 
// the following console.log doesn't fire like it used to in rc.4 
    this.portfolio.subscribe(val => console.log("received", val)); 
    this.stocksService.loadPortfolio(); 
    } 

} 
+0

あなたのコードされている必要があります正しく見える、私はこの問題は、どこか別の場所だと思います... – martin

答えて

0

私は問題を自分で解決にうまく働きました。間違いはサービスのコンストラクタにありました。

constructor(private apiService: ApiService) { 
    this._portfolio = BehaviorSubject.create(); 
} 

constructor(private apiService: ApiService) { 
    this._portfolio = new BehaviorSubject(""); 
} 
関連する問題