#javascript #angular
Вопрос:
Как я могу выполнить первую функцию, а затем на основе ответа первой функции я хочу выполнить свою вторую функцию в Angular.
this.auth.user.subscribe((user) => {
this.uid = user.uid;
this.service.getProfile(this.uid).subscribe((res) => {
this.registerData = res.document;
console.log(this.registerData);
});
});
this.service.getLeaderboardData(this.registerData?.profile_id).subscribe((res) => {
console.log(res.document.records);
})
registerData = {
profile_fullname: "",
profile_mobile: "",
profile_email: "",
profile_distId: "",
profile_taluka: "",
profile_password: "",
profile_uid: "",
profile_id: ""
};
Ответ №1:
Вам необходимо использовать swithcMap, например
_httpClient.get('http://localhost:3000/api/my')
.pipe(
switchMap(output => _httpClient.get(`http://localhost:3000/api/${output}`))
)
.subscribe(output2 => alert(output2));
_httpClient.get('http://localhost:3000/api/my')
— вот твои функции
funnction1
.pipe(
switchMap(result=> function2(result))
)
.subscribe(result2 => alert(result2));
Комментарии:
1. но я хочу вызвать свой файл component.ts, который не находится в сервисе.ts
2. const переключено = из(1, 2, 3).канал(карта переключения ((x: число) => из(x, x ** 2, x ** 3))); переключено.подписаться(x =>> консоль.журнал(x));
3. это пример двух функций