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 TypeSummaryObject
Promise

Deprecated in favor of promiseUtils.create().

more details
more detailsrequireUtils

Method Details

when(moduleRequire, moduleNames){Promise}static
Deprecated
  • since version 4.10

Deprecated in favor of promiseUtils.create(). 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
// like this starting at 4.10
require([
  "esri/core/promiseUtils"
], function( promiseUtils ) {
  // load modules based on whether a user selects
  // a UI option to apply class breaks to a layer
  if (classBreaksSelected) {
    return promiseUtils.create(function(resolve, reject) {
      require([ "esri/renderers/ClassBreaksRenderer" ], resolve);
    }).then(function(ClassBreaksRenderer) {
      // 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
Loading...