I’m sure the answer has to be out there but I can’t quite seem to find the case that I’m looking for. I’ll explain this in non-angular code in a simplistic made up example.
In any rational language it would look something like this:
public Book CreateBook(Book theBook)
{
//theBook is an object submitted by client code.
//it has 2 properties missing, call them “Property1” and
//“Property2”
//Property1 is filled in by calling one service
theBook.Property1 = service1.GetMeMyValue();
//Property2 is filled in automatically by the second service
//and the updated value is returned. Property1 MUST be filled in before
//this is called.
theBook = service2.SaveBook(theBook);
return theBook;
}
Angular HTTP calls always return Observables. I can't find the magic sequence of passing the buck to get this to work. The closest I can come in Angular speak is:
createBook(theBook : Book) : Observable<Book>
{
return this.http.get("http://service1/someEndpoint")
.map(item => {
theBook[“Property1”] = item.json()[“Property1”];
//something next here or outside? Outside most likely.
});
}
Anything I try with this returns null/undefined regardless of what I do with the inner values (or any modification I try to the outer return).
I’m sure the solution is quite obvious for anyone used to Angular (which is slightly better than JavaScript’s S&M syntax), but it quite escapes me and I’m hoping someone can nudge me in the right direction.