requireUtils

require(["esri/core/requireUtils"], function(requireUtils) { /* code goes here */ });
Object: esri/core/requireUtils
Since: ArcGIS API for JavaScript 4.3

Provides a convenience function that allows you to dynamically load required modules.

Method Overview

NameReturn TypeSummary
Promise

Dynamically requires one or more modules and returns a promise that resolves when all the specified modules have loaded.

more details
more details

Method Details

when(moduleRequire, moduleNames){Promise}static

Dynamically requires one or more modules and returns a promise that resolves when all the specified modules have loaded.

Parameters:
moduleRequire require

The require function used to load the modules. This is the AMD alias (e.g. the moduleRequire reference in the snippets below) used to reference the require module.

moduleNames String[] | String

The names of the modules to load.

Returns:
TypeDescription
PromiseA promise which resolves with an array containing the loaded modules, or a single module when moduleNames is a string.
Examples:
// Load multiple modules conditionally
require([
  "esri/core/requireUtils",
  "require",
  "dojo/domReady!"
], function( requireUtils, moduleRequire ){
  // load modules based on whether a user selects
  // a UI option to apply class breaks to a layer
  if(classBreaksSelected){
  {
    requireUtils.when(moduleRequire, [
      "esri/renderers/ClassBreaksRenderer",
      "esri/symbols/PolygonSymbol3D",
      "esri/symbols/ExtrudeSymbol3DLayer",
    ]).then(function([
      ClassBreaksRenderer,
      PolygonSymbol3D,
      ExtrudeSymbol3DLayer
    ]){
      // Create renderer and apply it to the desired layer

    });
  }
});
// Load a single module conditionally
require([
 ...  // load other modules as needed
 "esri/core/requireUtils",
 "require",
 "dojo/domReady!"
 ], function(..., requireUtils, moduleRequire) {
  if (basemapUrl && view) {
    // if basemapUrl is provided then
    // load customBasemap module and set up and
    // custom basemap with provided layers.
    requireUtils.when(moduleRequire, "./customBasemap")
     .then(function (Basemap) {
       var customBasemap = new Basemap({
         baseLayers: [layers],
         title: "Custom Basemap",
         id: "myBasemap"
       });
     });
  }
});

API Reference search results

NameTypeModule

There were no match results from your search criteria.