Angular CLI - 找不到 Dojo 模块

Angular Cli - Dojo module not found

我正在使用 Argis 4.8 JS api 开发 angular 应用程序。我需要 Dojo / On 功能。我也没有在编译器中收到错误。但是当我编译时,我得到错误"Module not found: Error: Can not resolve 'dojo / on' path"。我无法使用 Dojo class。我该怎么办?

我的完整代码

import {Component, OnInit, ViewChild, ElementRef, Input, Output, EventEmitter} from '@angular/core';
import {loadModules} from 'esri-loader';
import esri = __esri;
import on = require('dojo/on');


function executeIdentifyTask(event: Event | undefined) {
  console.log(event);
}

@Component({
  selector: 'app-esri-map',
  templateUrl: './esri-map.component.html',
  styleUrls: ['./esri-map.component.css']
})

export class EsriMapComponent implements OnInit {

  @ViewChild('mapViewNode') private mapViewEl: ElementRef;

  constructor() {
  }

  map: esri.Map;
  mapView: esri.MapView;
  layer: esri.MapImageLayer;
  identifyTask: esri.IdentifyTask;

  async initializeMap() {

    try {
      const [EsriMap, EsriMapView, MapImageLayer, IdentifyTask, IdentifyTaskProperties] = await loadModules([
        'esri/Map',
        'esri/views/MapView',
        'esri/layers/MapImageLayer',
        'esri/tasks/IdentifyTask',
        'esri/tasks/support/IdentifyParameters'
      ]);


      this.map = new EsriMap({
        basemap: 'dark-gray'
      });


      this.mapView = new EsriMapView({
        container: this.mapViewEl.nativeElement,
        center: [27.1428, 38.4237],
        zoom: 15,
        map: this.map
      });

      this.layer = new MapImageLayer(
        {url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer'});

      this.map.add(this.layer);
      this.mapView.when(function () {
        on(this.mapView , 'click' , executeIdentifyTask);
      });

    } catch (error) {
      console.log('We have an error: ' + error);
    }

  }

  ngOnInit() {
    this.initializeMap();
  }

}

我知道我来晚了一点,但对于遇到类似问题的其他人,我发现这些错误被描述为您可以按 F12 键并找到类型,但无法找到正确编译,通常是由于没有将类型放在 tsconfig.app.json.

中的 types: [] 数组中

我在 __esri 导入时遇到了类似的问题,并不断收到以下错误 ERROR in src/app/esri-map/esri-map.component.ts(16,15): error TS2503: Cannot find namespace '__esri'.,在将 "arcgis-js-api" 添加到我的 tsconfig.app.json 后,我的问题就解决了。