asp.net-mvc - 在 Angular 6 中使用解析器检索数据,但在对象中,数组为空。为什么?
问题描述
我有一个路径“用户/编辑”来编辑当前登录的用户。我有一个标签,我想编辑每个用户都有的“食谱”数组。我正在使用解析器获取有关用户的数据。我得到了他所有的食谱。问题是每个食谱都有一个“照片”数组,每个“食谱”的这个数组都是空的。我怎么能得到这些数据?
这是我的解析器
export class UserDetailResolver implements Resolve<User> {
constructor(private userService: UserService, private router: Router,
private authService: AuthService, private notif: NgxNotificationService )
{}
resolve(route: ActivatedRouteSnapshot): Observable<User> {
return this.userService.getUser(this.authService.decodedToken.nameid).pipe(
catchError(error => {
this.notif.sendMessage('Problem retrieving data', 'warning', 'bottom-right');
this.router.navigate(['/users']);
return of(null);
})
);
}
}
用户编辑组件:
export class UserEditComponent implements OnInit {
user: User;
recipes: Recipe[];
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.data.subscribe(data => {
this.user = data['user'];
});
在我的应用程序的其他部分,我可以毫无问题地显示所有食谱及其照片,并制作了一个画廊,一切都很好。也许我应该使用第二个解析器来解析数组中的每个配方,但我能做到吗?
解决方案
我找到了答案,问题出在 api 中。我没有在回复中包含我的照片。如果管理员决定删除问题或锁定它。
推荐阅读
- python - 删除时的 django-dynamic-formset 问题
- html - 无法让 VSCode 建议 html 数据属性(data-rel、data-theme、data-position 等...)
- html - 为什么`border-collapse:collapse`会导致相邻单元格在未绘制时具有顶部边框
- tsql - 防止 Ctrl+Z 在 Script As->Alter View 之后删除 SSMS 中的最后一行
- javascript - javascript中的功能不可变方式根据项目的条件在某些位置复制带有附加项目的数组
- javascript - 如何在反应中使用带有 API 调用的 redux?
- websphere - 在运行时替换 Websphere 数据源中的密码
- java - 将 HTTP 请求/响应与 RabbitMQ 中的异步消息集成
- sql - 尝试在 SQL Server 中重写 Access 查询
- css - 如何将 div 放在屏幕两侧而不是页面内容的其余部分?