From 042b834c7be68d324e91141d332c83bf6e83c34d Mon Sep 17 00:00:00 2001 From: brenmat Date: Thu, 6 Jun 2019 00:29:17 +0800 Subject: [PATCH] Add files via upload --- ngAutocomplete.js | 169 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 ngAutocomplete.js diff --git a/ngAutocomplete.js b/ngAutocomplete.js new file mode 100644 index 0000000..fe1be2c --- /dev/null +++ b/ngAutocomplete.js @@ -0,0 +1,169 @@ +'use strict'; + +/** + * A directive for adding google places autocomplete to a text box + * google places autocomplete info: https://developers.google.com/maps/documentation/javascript/places + * + * Usage: + * + * 0){ + autocompleteService.getPlacePredictions( + { + input: result.name, + offset: result.name.length + }, + function listentoresult(list, status) { + if(list == null || list.length == 0) { + + scope.$apply(function() { + scope.details = null; + }); + + } else { + var placesService = new google.maps.places.PlacesService(element[0]); + placesService.getDetails( + {'reference': list[0].reference}, + function detailsresult(detailsResult, placesServiceStatus) { + + if (placesServiceStatus == google.maps.GeocoderStatus.OK) { + scope.$apply(function() { + + controller.$setViewValue(detailsResult.formatted_address); + element.val(detailsResult.formatted_address); + + scope.details = detailsResult; + + //on focusout the value reverts, need to set it again. + var watchFocusOut = element.on('focusout', function(event) { + element.val(detailsResult.formatted_address); + element.unbind('focusout') + }) + + }); + } + } + ); + } + }); + } + } + + controller.$render = function () { + var location = controller.$viewValue; + element.val(location); + }; + + //watch options provided to directive + scope.watchOptions = function () { + return scope.options + }; + scope.$watch(scope.watchOptions, function () { + initOpts() + }, true); + + } + }; + }); \ No newline at end of file