import { Component , OnInit } from '@angular/core' ; import { ViewController } from 'ionic-angular' ; declare var google ; @ Component ( { selector : 'page-modal-autocomplete-items' , templateUrl : 'modal-autocomplete-items.html' } ) export class ModalAutocompleteItems implements OnInit { autocompleteItems : any ; autocomplete : any ; acService : any ; placesService : any ; constructor ( public viewCtrl ) { } ngOnInit ( ) { this . acService = new google . maps . places . AutocompleteService ( ) ; this . autocompleteItems = [ ] ; this . autocomplete = { query : '' } ; } dismiss ( ) { this . viewCtrl . dismiss ( ) ; } chooseItem ( item ) { console . log ( 'modal > chooseItem > item > ' , item ) ; this . viewCtrl . dismiss ( item ) ; } updateSearch ( ) { console . log ( 'modal > updateSearch' ) ; if ( this . autocomplete . query == '' ) { this . autocompleteItems = [ ] ; return ; } let self = this ; let config = { types : [ 'geocode' ] , input : this . autocomplete . query , componentRestrictions : { country : 'AR' } } ; this . acService . getPlacePredictions ( config , function ( predictions , status ) { console . log ( 'modal > getPlacePredictions > status > ' , status ) ; self . autocompleteItems = [ ] ; predictions . forEach ( function ( prediction ) { self . autocompleteItems . push ( prediction ) ; } ) ; } ) ; } }