RxJs. why don't the two subscriptions into one observable?

there is an observable created from Subject:
private searchData$: Observable<ISearchData>;

 constructor (private conService: ConnectionService) {
 this.searchData$ = <Observable<ISearchData>>conService.messages.pipe(
 filter((message) => {
 return message.key === QUERYBASE.search.key;
}),
 map ((message)=>{
 return message.data as ISearchData;
})
);
 }

there is a method which sends the request, after which messages appear in the messages which pass the filter, and subscribes to the searchData$
public startSearch(){
 let queryData: ISearchQueryData = ...

 this.searchDataSub = this.searchData$.subscribe(
(data)=>{
 console.log("Get search data: ",data);
 if (data.hash !== this.lastHash) {
 this.items = data.search;
 this.lastHash = data.hash;
}
 this.searchDone = data.done;
}
);
 const newSub = this.searchData$.pipe(
delay(2000)
).subscribe(
 (data)=> {
 console.log("sub2", data);
 //!data.done && this.conService.search(queryData);
}
);

this.conService.search(queryData);
 }


if a second subscription cut - first works (in the console there is a "Get search data: , ...", the data is processed)
and if you leave both, why something works is only the second subscription!! (console only "sub2, ...", no data)

Of course, I can insert a crutch and leave only the first subscription in which the timeout to send a request, but damn all the tutorials say that you can do two .subscribe to one observable, without any frills, so why I have it is not working?

.pipe to clean tried the same game, only works a second subscription:
this.searchDataSub = this.searchData$.subscribe(
(data)=>{
 console.log("Get search data: ",data);
/*...*/
}
);
 const newSub = this.searchData$.subscribe(
 (data)=> {
 console.log("sub2", data);
//...
}
 );

so console only sub2
March 19th 20 at 08:43
1 answer
March 19th 20 at 08:45
Solution

Find more questions by tags Reactive ExtensionsAngularJavaScript