小编Rad*_*ghe的帖子

TS2564 属性 mapViewEl 没有初始值设定项

我正在努力获取适用于 Angular (v4) 的 ArcMap Javascript,以在 Angular (v10) 项目中显示地图。我发现的所有代码示例(此处ESRI 官方此处、stackblitz此处)都非常相似。viewChild 是这样创建的:

export class EsriMapComponent implements OnInit, OnDestroy {
@ViewChild("mapViewNode", { static: true }) private mapViewEl: ElementRef;
view: any;
constructor() { }
Run Code Online (Sandbox Code Playgroud)

但我的 IDE 告诉我TS2564 Property mapViewEl has no initializer and is not definitely assigned in the constructor

我可以将此行更改为:

@ViewChild("mapViewNode", { static: true }) private mapViewEl!: ElementRef;
Run Code Online (Sandbox Code Playgroud)

地图已绘制,但我不喜欢删除 Typescript 保护,特别是因为我在网上找到的任何工作示例都没有这样做。

esri-map.component.html 非常简单:<div #mapViewNode></div>

如何修复 TS2564 错误?

arcmap typescript angular

5
推荐指数
1
解决办法
1610
查看次数

标签 统计

angular ×1

arcmap ×1

typescript ×1