2
他們之間有什麼區別,何時以及如何使用它們?我讀了這個主題相當於一個EventEmitter。RxJs中的主題和Angular2中的EventEmitter
如果我想重寫這個,怎麼樣?
import { Injectable} from '@angular/core';
import { Subject,BehaviorSubject } from 'rxjs';
import {Playlists} from 'channel' /** Assumes this is where you have defined your Playlists interface **/
@Injectable()
export class PlaylistService {
private _currentPlaylists$: Subject<Playlists> = new BehaviorSubject<Playlists>(null);
constructor() {}
currentPlaylists() {
return this._currentPlaylists$.asObservable();
}
setCurrentPlaylists(playlists:Playlists){
this._currentPlaylists$.next(playlists);
}
}
見http://stackoverflow.com/questions/36076700/what-is-the-proper-use-of-an-eventemitter正確使用EventEmitter的。 –