【发布时间】:2020-03-21 12:57:24
【问题描述】:
我已经搜索了一个解决方案,但它们都不起作用。
点击按钮编辑后,它会将我重定向到编辑事件,我得到:
错误类型错误:无法读取未定义的属性“类别”
ngOnInit() {
this.eventService
.getEventById(this.route.snapshot.params.id)
.subscribe((ev) => this.event = ev);
订阅后,如果我这样做:console.log(this.event) 它返回我未定义。
而.subscribe(console.log(ev)); 给我一个对象。
不知道为什么this.event = ev 不起作用我已经在另一个组件中使用过它并且映射有效。
服务:
getEventById(id) {
return this.httpClient.get<EventsDto>(this.urlevent + '?id=' + id);
}
在 edit-event.component.html 中,打印了 {{event.name}} 这怎么可能
如果 this.event 像我们之前看到的那样未定义:.subscribe((ev) => this.event = ev)
【问题讨论】:
-
在订阅中添加断点,然后在打开网络选项卡的情况下重新创建问题。您应该看到在订阅内发送的出站打包。这应该告诉您结果是您所期望的。
标签: angular typescript asynchronous undefined