在爱奥尼亚2中,集成了AutocompleteService(),但不起作用;s在运行时显示类似的消息

在爱奥尼亚2中,集成了AutocompleteService(),但不起作用;s在运行时显示类似的消息,autocomplete,ionic2,Autocomplete,Ionic2,在这行代码中,我得到如下所示的错误。 //自动完成 import {Component, NgZone} from '@angular/core'; import {ViewController} from 'ionic-angular'; declare var google:any; @Component({ templateUrl: 'autocomplete.html' }) export class AutocompletePage { autocompleteItems;

在这行代码中,我得到如下所示的错误。 //自动完成

import {Component, NgZone} from '@angular/core';
import {ViewController} from 'ionic-angular';
declare var google:any;

@Component({
  templateUrl: 'autocomplete.html'
})

export class AutocompletePage {
  autocompleteItems;
  autocomplete;
  service = new google.maps.places.AutocompleteService();

  constructor (public viewCtrl: ViewController, private zone: NgZone) {
    this.autocompleteItems = [];
    this.autocomplete = {
      query: ''
    };
  }

  dismiss() {
    this.viewCtrl.dismiss();
  }

  chooseItem(item: any) {
    this.viewCtrl.dismiss(item);
  }

  updateSearch() {
    if (this.autocomplete.query == '') {
      this.autocompleteItems = [];
      return;
    }
    let me = this;
    this.service.getPlacePredictions({ input: this.autocomplete.query, componentRestrictions: {country: 'IN'} }, function (predictions, status) {
      me.autocompleteItems = []; 
      me.zone.run(function () {
        predictions.forEach(function (prediction) {
          me.autocompleteItems.push(prediction.description);
        });
      });
    });
  }
}
上面是我在文件中编写的代码,用于从GoogleAPI获取autocompleteservice 上面附上运行时出错的照片

这里有个错误

service = new google.maps.places.AutocompleteService();
我不知道为什么会这样。
谢谢。

我通过更改爱奥尼亚2中index.html中的脚本来解决我的问题:

//首先,我有下面的脚本,只需从api中删除
&callback=initMap
,或者复制粘贴我在下面编写的第二个脚本:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places&callback=initMap"
    async defer></script>

替换为:

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>


你需要通过编辑你的问题来提供相关的代码。添加你设置的组件,否则没有人知道。你还没有声明
google
<代码>声明var google:any在导入之后和类之前仍然有相同的错误。我已经尝试过了,但没有成功@苏拉杰,我知道我是按照你的建议编辑代码的。