Итак, я пытаюсь создать ввод для автозаполнения для ГОСА, пока все хорошо, но когда я помещаю компонент (app-agm-input) в свой app.component.html, я получаю следующую ошибку:
Вот как выглядит мой компонент:
import {
Component,
OnInit,
ViewChild,
ElementRef,
NgZone,
Input
} from "@angular/core";
import { MapsAPILoader } from "@agm/core";
import {} from "@types/googlemaps";
@Component({
selector: "app-agm-input",
templateUrl: "./agm-input.component.html",
styles: []
})
export class AgmInputComponent implements OnInit {
@ViewChild("agmInput") public searchElement: ElementRef;
@Input() placeholder: string;
constructor(private mapsAPILoader: MapsAPILoader, private ngZone: NgZone) {}
ngOnInit() {
this.mapsAPILoader.load().then(() => {
let autocomplete = new google.maps.places.Autocomplete(
this.searchElement.nativeElement,
{ types: ["address"] }
);
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
if (
place.geometry === undefined ||
place.geometry === null
) {
return;
}
});
});
});
}
}
Вот как выглядит мой модуль:
import { NgModule } from "@angular/core";
import { AgmInputComponent } from "./agm-input.component";
import { SharedModule } from "../../shared.module";
import { AgmCoreModule } from "@agm/core";
@NgModule({
imports: [
SharedModule,
AgmCoreModule.forRoot({
apiKey: "**key**",
libraries: ["places"]
})
],
declarations: [AgmInputComponent],
exports: [AgmInputComponent]
})
export class AgmInputModule {}
ПРИМЕЧАНИЕ Я удалил ключ API для ознакомления.
А вот так выглядит html-файл моего компонента:
<input class = "input" type = "search" placeholder = "{{placeholder}}" autocorrect = "off" autocapitalize = "off" spellcheck = "off" #agmSearch>



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Вы имеете в виду неправильное имя переменной
сделайте свой код вот так -
@ViewChild("agmSearch") public searchElement: ElementRef;
Да, в больших проектах я всегда пренебрегаю мелочами. Спасибо тебе за это! :)