У меня есть код, в котором наблюдаемое выполняется перед кодом, который предшествует ему, и значение, которое оно должно использовать для запроса данных (this.currentAccount.id
), еще не достигнуто, когда оно выполняется.
Как я могу изменить его, чтобы убедиться, что идентификатор есть?
Мне нужно иметь значение: this.currentAccount.id; перед запросом query ['userId.equals'] = this.currentAccount.id; выполняется.
console.log('Print 1st: ', this.currentAccount.id);
печатается после console.log('Print second', this.users);
ngOnInit() {
this.isSaving = false;
this.principal.identity().then(account => {
this.currentAccount = account;
console.log('Print 1st: ', this.currentAccount.id);
});
this.activatedRoute.data.subscribe(({ community }) => {
this.community = community;
});
const query = {
};
if ( this.currentAccount.id != null) {
query['userId.equals'] = this.currentAccount.id;
}
this.userService
.query(query)
.subscribe(
(res: HttpResponse<IUser[]>) => {
this.users = res.body;
},
(res: HttpErrorResponse) => this.onError(res.message)
);
console.log('Print second', this.users);