Harlan Wescott
Harlan Wescott

Reputation: 289

ArcGIS Javascript in AngularJS App - Error Loading Modules

I have an AngularJS application which is using the ArcGIS API for JavaScript to display a map.

I have been using individual require statements such as:

var esriMap = require("esri/map");

This has worked fine for all modules EXCEPT for Dojo layout Dijits. When I try to add a require statement like this:

var Scalebar = require("esri/dijit/Scalebar");

I get the following error:

Error: undefinedModule(…) "Error: undefinedModule at Error (native) at d (http://js.arcgis.com/3.12/init.js:15:382) at La (http://js.arcgis.com/3.12/init.js:24:296) at r (http://js.arcgis.com/3.12/init.js:15:476)

I would like to keep using the individual require statements if possible. Is there any reason why I would be getting this error only on the dijit modules?

Upvotes: 1

Views: 443

Answers (2)

Tom Wayson
Tom Wayson

Reputation: 1197

Also, I don't know if you've seen this, but Esri does have some angular modules that help integrate maps into Angular apps:

https://github.com/Esri/angular-esri-map

That includes a service called esriLoader that wraps Dojo's require and allows you to either pass a callback that will receive the modules or get a promise that is resolved as an array with the modules.

Upvotes: 2

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

Single-argument require only works for modules that have already been loaded. Judging by the undefinedModule error, you're trying to use single-argument require on modules that were never loaded. To reference modules that have not yet been loaded, you need to use the standard AMD require syntax:

require([
    'dijit/layout/StackContainer',
    ...
], function (StackContainer, ...) {
    ...
});

It's usually simplest to always use this format. (It could also be considered more reliable, since otherwise you're likely relying on assumptions that the modules you're using have already been loaded, whether directly or indirectly as dependencies.)

Upvotes: 3

Related Questions