private selectedDocuments$: BehaviorSubject<Document[]> = new BehaviorSubject<Document[]>([]);
public selectedDocumentsFilesIds$ = this.selectedDocuments$.pipe(map((docs) => docs.map((doc) => doc.iD_FILE))).pipe(shareReplay(1));
I add a new values using this:
setSelectedDocuments(documents: Document[]): void {
this.selectedDocuments$.next(documents);
}
I try to get last emitted values from selectedDocumentsFilesIds$ inside component:
public onClick() {
this.documentsRepository.selectedDocumentsFilesIds$.toPromise().then((ids: number[]) => {
if (ids.length == 0) {
return;
}
});
}
Why it does not work for me, there are any errors.
But this works:
this.documentsRepository.selectedDocumentsFilesIds$.subscribe((r) => console.log(r));
I have tried this:
public createReestr() {
this.documentsRepository.selectedDocumentsFilesIds$
.pipe(
tap((ids: number[]) => {
if (ids.length == 0) {
return throwError('Message');
}
}),
filter((ids: number[]) => ids.length > 0),
tap((ids: number[]) => (this.dialogConfig.data = { data: { ids }, width: '500px' })),
concatMap(() =>
this.dialog
.open(DialogDocumentCreateRegisterComponent, this.dialogConfig)
.afterClosed()
.pipe(
filter(Boolean),
concatMap((data: { date: Date; ids: number[] }) =>
this.documentsRepository.CreateMailReestrById(data.ids, data.date),
),
indicate(this.createReestrloading$),
handleResponseMessage(this.messageService),
),
),
)
.subscribe(() => {}, (e) => alert(e));
}