If I understand your question correctly, you don't want the first part of the method to be evaluated until the user subscribes. So if initially the user object had a null password, then the password was set on that object, and then the observable was subscribed to, you'd want the result to be the result from http.put()
.
In the example below, the user is wrapped into an observable and the rest of the execution of the pipe won't run until the observable is subscribed to.
saveNewUser(user: User): Observable<boolean> {
return of(user).pipe(
switchMap(u => (!u || !u.password) ? of({ ok: false }) : this.http.put(this.saveUrl, u)),
map(res => res.ok)
);
}
This is a pretty awkward way of doing things. For one thing this simply won't work if the object passed is initially undefined or the reference on the outside is changed. Much better would be creating on Observable on any changes to the user and piping the rest of the logic or just simply waiting to call saveNewUser()
until after the data is set.