我正在努力获取适用于 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 错误?