2
それらの違いは何ですか?それらの使用方法と使用方法は何ですか? SubjectはEventEmitterに相当すると読んでいます。RxJsのSubjectとAngular2のEventEmitter
これを書き直したい場合はどうすればよいですか?他の例では
@Output()
someEvent: EventEmitter = new EventEmitter();
それが関係していないことから、あなたはSubject
S(Rxjsから)を使用することができます。■Output
デコレータでAngular2コンポーネントのカスタムイベントを実装する場合にのみ使用する必要があります
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の –