Answer the question
In order to leave comments, you need to log in
How to return an observer?
I have a function in a service to add a document:
addDocument(data: ExistingRelationShips) {
return this.applicationExistingRelationShipsService
.create(data)
.pipe(tap((document) => this.documents.next(this.documents.getValue().concat(document))))
}
this.documents.next(this.documents.getValue().concat(document))
this.service.addDocument().subscribe((res) => console.log(res));
Answer the question
In order to leave comments, you need to log in
fetchDocuments(data) {
return this.documents.pipe(
switchMap(documents => forkJoin([
of(documents),
this.applicationExistingRelationShipsService.create(data)
])),
map(([state, update]) => [...state, ...update]),
tap(state => this.documents.next(state)),
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question