Reputation:
As described in the entity dataservice documentation , the add operation expects an entity to be saved on the backend. What it doesn't say is that it expects the created entity to be returned from the backend (with an ID etc). My backend does that and it works as expected, however
when I tap into the add operation, which returns an Observable, at least my IDE gives me Observable methods to continue... it's best demonstrated with a piece of code
this.myEntityService.add(myNewEntity).pipe(
tap(data => console.log('data:', data))
)
Nothing is logged to the console at all.
My question is, how do I get what's returned from the HTTP service? e.g. the entity, persisted to the backend database?
Upvotes: 2
Views: 138
Reputation:
The problem was, I didn't subscribe to the Observable that add
returns.
I assumed the data is being emitted regardless of a subscription.
So the correct way to receive the result is
this.myEntityService.add(myNewEntity).subscribe(data => {
console.log('data:', data);
});
subscribing to it.
Upvotes: 2