我想从api检索数据并将其分配给角度分量内的某个值。在subscribe
中,我尝试将数据分配给loggedUser
,然后在此内部调用函数以使用此接收到的对象导航到另一个组件。不幸的是,我得到了错误:请求的路径在索引1处包含未定义的段。我也想在订阅之外设置此对象。我该如何实现?
logIn() {
this.portfolioAppService.logIn(this.loggingUser).subscribe((data) => {
this.loggedUser = data;
console.log(this.loggedUser);
console.log(data);
this.navigateToProfile(this.loggedUser.Id);
});
}
navigateToProfile(id: number) {
this.router.navigate(['/profile', id]);
}
调用navigateToProfile
时使用的名称不正确。