BehaviorSubject
immediately emits the last value to new subscribers:
@Injectable()
export class SearchService {
private searchResultSource = new BehaviorSubject<string>('');
setSearchResults(_searchResult: string): void {
this.searchResultSource.next(_searchResult);
}
}
ReplaySubject
emits all previous events to new subscribers.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…