UNPKG

ngx-google-place-autocomplete

Version:

* A simple and lightweight google place autocomplete directive for Angular2

155 lines (146 loc) 6.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('ngx-google-place-autocomplete', ['exports', '@angular/core'], factory) : (factory((global['ngx-google-place-autocomplete'] = {}),global.ng.core)); }(this, (function (exports,i0) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxGooglePlaceAutocompleteService = /** @class */ (function () { function NgxGooglePlaceAutocompleteService() { } NgxGooglePlaceAutocompleteService.decorators = [ { type: i0.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ NgxGooglePlaceAutocompleteService.ctorParameters = function () { return []; }; /** @nocollapse */ NgxGooglePlaceAutocompleteService.ngInjectableDef = i0.defineInjectable({ factory: function NgxGooglePlaceAutocompleteService_Factory() { return new NgxGooglePlaceAutocompleteService(); }, token: NgxGooglePlaceAutocompleteService, providedIn: "root" }); return NgxGooglePlaceAutocompleteService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxGooglePlaceAutocompleteDirective = /** @class */ (function () { function NgxGooglePlaceAutocompleteDirective(elRef, zone) { this.zone = zone; this.onSelect = new i0.EventEmitter(); this.element = elRef.nativeElement; } /** * @return {?} */ NgxGooglePlaceAutocompleteDirective.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var autocomplete = new google.maps.places.Autocomplete(this.element); google.maps.event.addListener(autocomplete, 'place_changed', ( /** * @return {?} */function () { _this.zone.run(( /** * @return {?} */function () { /** @type {?} */ var place = _this.getFormattedAddress(autocomplete.getPlace()); if (place) { _this.onSelect.emit(place); } })); })); }; /** * @param {?} place * @return {?} */ NgxGooglePlaceAutocompleteDirective.prototype.getFormattedAddress = /** * @param {?} place * @return {?} */ function (place) { /** @type {?} */ var location_obj = { fullAddress: null, city: null, state: null, streetNumber: null, streetName: null, country: null, postalCode: null }; for (var i in place.address_components) { /** @type {?} */ var item = place.address_components[i]; location_obj['fullAddress'] = place.formatted_address; if (item['types'].indexOf('locality') > -1) { location_obj['city'] = item['long_name']; } else if (item['types'].indexOf('administrative_area_level_1') > -1) { location_obj['state'] = item['short_name']; } else if (item['types'].indexOf('street_number') > -1) { location_obj['streetNumber'] = item['short_name']; } else if (item['types'].indexOf('route') > -1) { location_obj['streetName'] = item['long_name']; } else if (item['types'].indexOf('country') > -1) { location_obj['country'] = item['long_name']; } else if (item['types'].indexOf('postal_code') > -1) { location_obj['postalCode'] = item['short_name']; } } return location_obj; }; NgxGooglePlaceAutocompleteDirective.decorators = [ { type: i0.Directive, args: [{ selector: '[ngx-google-place]' },] } ]; /** @nocollapse */ NgxGooglePlaceAutocompleteDirective.ctorParameters = function () { return [ { type: i0.ElementRef }, { type: i0.NgZone } ]; }; NgxGooglePlaceAutocompleteDirective.propDecorators = { onSelect: [{ type: i0.Output }] }; return NgxGooglePlaceAutocompleteDirective; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var NgxGooglePlaceAutocompleteModule = /** @class */ (function () { function NgxGooglePlaceAutocompleteModule() { } NgxGooglePlaceAutocompleteModule.decorators = [ { type: i0.NgModule, args: [{ declarations: [NgxGooglePlaceAutocompleteDirective], exports: [NgxGooglePlaceAutocompleteDirective] },] } ]; return NgxGooglePlaceAutocompleteModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ exports.NgxGooglePlaceAutocompleteService = NgxGooglePlaceAutocompleteService; exports.NgxGooglePlaceAutocompleteDirective = NgxGooglePlaceAutocompleteDirective; exports.NgxGooglePlaceAutocompleteModule = NgxGooglePlaceAutocompleteModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-google-place-autocomplete.umd.js.map