I have a service with a subject:
@Injectable() export class UserService() {
private currentUserSubject = new BehaviorSubject<User>(null);
public currentUser = this.currentUserSubject.asObservable().distinctUntilChanged();
... // emitting new User
}
Have a component I inject this service into and subscribing on updates:
@Component() export class UserComponent {
constructor(private userService: UserService) {
this.userService.currentUser
.subscribe((user) => {
// I want to see not null value here
})
}
}
I want to apply something to Observable<User>
to filter all null values and get into subscribe only when User
is actually loaded.
Observable.filter
. – Myasthenia