How to use geocoder in the project Angular 2+?

Good evening comrades!
I need to do the work in Angular using Yandex maps. First, I created a project Angular 2+ according to the instructions, set a special component of npm angular2-yandex-maps. This component is all good, has rich functionality, well-documented, there are many code examples. But to use it to build on I cards does not work, and I need.
Then I went the other way, set the component ymaps according to instructions. In file polyfills.ts added a line
(window as any).global = window;

the file of my component did
import ymaps from 'ymaps';

In General it was a code like this:
import {Component, the OnInit} from '@angular/core';
import ymaps from 'ymaps';

@Component({
 selector: 'app-root',
 templateUrl: './app.component.html',
 styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
 map: any;
 points = ['Moscow, Smolenskaya', 'Moscow, metro Arbatskaya', [55.734876, 37.59308]];
 multiRoute: any;

 ngOnInit() {
 ymaps.load('https://api-maps.yandex.ru/2.1/?lang=ru_RU').then(maps => {
 this.map = new maps.Map('map', {
 center: [55.75, 37.6],
 zoom: 8,
 controls: ['geolocationControl', 'zoomControl']
});
 this.multiRoute = new maps.multiRouter.MultiRoute({
 referencePoints: this.points
 }, {
 boundsAutoApply: true,
 reverseGeocoding: true,
 viaPointDraggable: true
});
 new maps.geocode('Moscow', {result: 1}).then(res => {
console.log(res);
 }, err => {
console.log(err);
});
this.renderRoute();
})
 .catch(error => console.log('Failed to load Yandex Maps', error));
}

 addPoint(point: string) {
 if (point === ") {
return;
}
this.points.push(point);
this.updateRoute();
this.geoCoder(point);
 // this.map.setCenter([55.818, 37.513]);
}

 dellPoint(i: number) {
 this.points.splice(i, 1);
this.updateRoute();
}

 renderRoute() {
this.map.geoObjects.add(this.multiRoute);
this.multiRoute.editor.start();
}

 updateRoute() {
this.multiRoute.model.setReferencePoints(this.points);
 this.map.options.set('mapStateAutoApply', true);
}

 geoCoder(point: any) {
 new ymaps.geocode('Moscow', {result: 1}).then(res => {
console.log(res);
 }, err => {
console.log(err);
});
}
}

Everything works fine. The map is created, the route will be created. But how to use geocoder in this project, I don't know. If I execute the code inside the ngOnInit, it's all good, get the object in the console.
ngOnInit() {
 ymaps.load('https://api-maps.yandex.ru/2.1/?lang=ru_RU').then(maps => {
 new maps.geocode('Moscow', {result: 1}).then(res => { console.log(res); }, err => { console.log(err); });
});
}


If I execute the same code in a separate function, I get the error
ERROR TypeError: "ymaps__WEBPACK_IMPORTED_MODULE_1___default.a.geocode is not a constructor"


geoCoder(point: any) {
 new ymaps.geocode('Moscow', {result: 1}).then(res => {
console.log(res);
 }, err => {
console.log(err);
});
 }

And I need to use a geocoder in a separate function inside my component and pass it the parameters. How to be?
March 12th 20 at 08:10
1 answer
March 12th 20 at 08:12
Solution
If I execute the same code

it's not the same code
ymaps.load('https://api-maps.yandex.ru/2.1/?lang=ru_RU').then(maps => {
 new maps
})

and
new ymaps
the difference is obvious
I agree, not this one. But how to make to work the function? - clark commented on March 12th 20 at 08:15
@clark, the typical response is to take the code that already works. First, Yes?
geoCoder(point: any) {
 ymaps.load('https://api-maps.yandex.ru/2.1/?lang=ru_RU').then(maps =>
 new maps.geocode('Moscow', {result: 1}).then(res => {
console.log(res);
 }, err => {
console.log(err);
});
);
 }
- ottis_Beah commented on March 12th 20 at 08:18
Yes indeed, it worked. Thank you so much. - clark commented on March 12th 20 at 08:21

Find more questions by tags TypeScriptnpmYandex.MapsAngular