modules.require
Static function.
Request to get modules.
Returns a promise object that is confirmed by the requested modules. Or it is rejected, if an error occurred. For example, one of the requested modules is missing in the module system.
{ vow.Promise } modules.require(modules[, successCallback[, errorCallback[, context]]])
Parameters:
Parameter |
Default value |
Description |
— |
Type: String|String[] Module name or array of module names. |
|
— |
Type: Function The function that is called after receiving all the modules. The requested entities will be passed to the function as arguments. The order of the arguments will match the order in the modules array. |
|
— |
Type: Function The function that will be called in case of an error. |
|
— |
Type: Object The execution context of the callback function. |
* Mandatory parameter/option.
Examples:
1.
// Requesting the 'Map' and 'Placemark' modules using a promise object.
ymaps.modules.require(['Map', 'Placemark'])
.spread(
function (Map, Placemark) {
var myMap = new Map("map", {
center: [55.72, 37.64],
zoom: 5
});
myMap.geoObjects.add(
new Placemark(myMap.getCenter())
);
},
function (error) {
// Error handling.
},
this
);
2.
// Requesting the 'Map' module.
ymaps.modules.require('Map')
.spread(
function (Map) {
var myMap = new Map("map", {
center: [55.72, 37.64],
zoom: 5
});
},
this
);
Mandatory parameter/option.