Я хочу использовать этот угловой код в строковом порядке и получить возвращенные значения:
transaction: ITransaction = new Transaction();
merchant: IMerchant;
const transactionid = this.route.snapshot.params['id'];
if (!transactionid) {
this.router.navigate(['panel', 'transactions']);
}
this.transactionService.get(transactionid)
.subscribe(value => {
if (value != null) {
this.transaction = value;
}
});
this.merchantService.get(this.transaction.merchant_id)
.subscribe(value => {
if (value != null) {
this.merchant = value;
}
});
console.log('value ' + this.merchant.name);
Но я получаю значение null для merchant_id, и второй запрос не выполняется должным образом.
Сначала я хотел бы загрузить файл TransactionService.get (params ['id']), используя идентификатор из ссылки http. Во-вторых, когда загружается объектная транзакция, я хотел бы загрузить get (action.merchant_id), используя unique_id, загруженный из первого запроса. Я попробовал это:
this.route.params.pipe(
tap( params => {
if (params['id']) {
return this.transactionService.get(params['id']);
} else {
return of(null);
}
}),
switchMap( value => this.merchantService.get(value.merchant_id) )
);
Как правильно это реализовать?