因为它在构建过程中显示错误。
app/pages/TestPage4/TestPage4.ts:27:27 中的错误 - 错误 TS2304:找不到名称“google”。27 this.geoCoder = 新的 google.maps.Geocoder; ~~~~~~ app/pages/TestPage4/TestPage4.ts:29:32 - 错误 TS2304:找不到名称“google”。
29 const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement); ~~~~~~ app/pages/TestPage4/TestPage4.ts:33:24 - 错误 TS2503:找不到命名空间“google”。
33 常量位置:google.maps.places.PlaceResult = autocomplete.getPlace(); ~~~~~~
下面是我的代码。
import { Component, OnInit, ElementRef, ViewChild, NgZone } from '@angular/core';
import { MapsAPILoader } from '@agm/core';
@Component({
selector: 'app',
templateUrl: './TestPage4.html',
styleUrls: ['./TestPage4.css']
})
export class TestPage4 implements OnInit {
lat: number;
lng: number;
zoom = 1;
private geoCoder;
@ViewChild('search', { static: false})
public searchElementRef: ElementRef;
constructor( …Run Code Online (Sandbox Code Playgroud) typescript angular google-places-autocomplete angular8 agm-core