I am currently working on implementing an ESRI map using esri-loader in my Angular application. Everything seems to be working fine, but I am encountering an error when typing something into the search widget and then focusing out of it.
"Uncaught TypeError: Cannot read property 'parentNode' of null
at HTMLInputElement.d (dojo.js:2209)
at Object.trigger (jquery.min.js:2)
at Object.simulate (jquery.min.js:2)
at HTMLDocument.n (jquery.min.js:2)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:498)
at invokeTask (zone.js:1693)
at HTMLDocument.globalZoneAwareCaptureCallback (zone.js:1762)
I am using version 4.14 of ESRI.
I have looked into this thread for a solution, but haven't been able to resolve it yet.
Here is my package.json:
"esri-loader": "^2.15.0"
For the code implementation, here is what I have:
import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from "@angular/core";
import { loadModules ,loadScript} from "esri-loader";
@Component({
selector: "app-esri-map",
template: `
<span> map component workes</span>
<div class="esri-view" #mapViewNode></div>
`,
styles: [`
@import url('https://js.arcgis.com/4.14/esri/css/main.css');
.esri-view {
height: 600px;
}`
]
})
export class MapComponent implements OnInit, OnDestroy {
// The <div> where we will place the map
@ViewChild("mapViewNode", { static: true }) private mapViewEl: ElementRef;
view: any;
constructor() {
loadScript();
}
async initializeMap() {
try {
// Load the modules for the ArcGIS API for JavaScript
const options = { version: '4.14', css: true };
const [Map, MapView, Search] = await loadModules(
["esri/Map",
"esri/views/MapView",
"esri/widgets/Search"],options);
// Configure the Map
const mapProperties = {
basemap: "streets"
};
const map = new Map(mapProperties);
// Initialize the MapView
const mapViewProperties = {
container: this.mapViewEl.nativeElement,
zoom: 10,
map: map
};
this.view = new MapView(mapViewProperties);
var search = new Search({
view: this.view,
searchTerm: `15 Inverness Way East, Englewood, CO80112, United States`,
});
console.log('search', search.search());
this.view.ui.add(search, "top-right");
search.on("select-result", function (event) {
console.log("The selected search result: ", event);
console.log('attributes', event.result.feature.attributes)
});
await this.view.when(); // wait for map to load
console.log('this.view', this.view);
return this.view;
} catch (error) {
console.error("EsriLoader: ", error);
}
}
ngOnInit() {
this.initializeMap();
}
ngAfterViewInit() {
}
ngOnDestroy() {
if (this.view) {
// destroy the map view
this.view.container = null;
}
}
}
Do you think there is a need to change some configuration? Any suggestions would be greatly appreciated.