Documentation
Reference
2.1.50 (current version)
collection
interactivityModel
Interfaces

ready

Static function.

Performs the passed function when the API and DOM are ready for use.

Returns the promise object that is verified by the API namespace, or rejected if an error occurred when loading.

Parameters:

ParameterDefault valueDescription
successCallback

Type: Function|Object

Function that will be called after successfully loading and initializing the API and DOM, or an object with parameters if the extended syntax is used.

Available parameters:

  • require — Array of additional modules that must be loaded with the API.
  • successCallback - Function that will be called when the API is loaded successfully.
  • errorCallback - Function that will be called if an error occurs.
  • context - Execution context for functions.

All parameters are optional.

The API namespace will be passed to successCallback.

errorCallback

Type: Function

The function that will be called if an error occurred during initialization. The error will be passed to the function.

context

Type: Object

Context for the function.

Examples:

1.

<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
    <script type="text/javascript">
    ymaps.ready(function () {
        var map = new ymaps.Map('map', {
            center: [55.7, 37.6],
            zoom: 10
        });
        // ...
    });
    </script>
</head>
<body>
    <div id="map" style="width: 500px; height: 500px;"></div>
</body>
</html>

2.

// Example using the extended syntax.
ymaps.ready({
    // successCallback will be called when the API and the "myModule1" module are loaded.
    require: ['myModule1'],
    successCallback: function (ym) {
        var map = new ymaps.Map('map', {
            center: [55.7, 37.6],
            zoom: 10
        });
        var obj = new ymaps.myModule1();
        // ...
    }
})