├── bower.json ├── examples ├── advanced.css ├── advanced.js └── advanced.html ├── README.md └── src └── ngAutocomplete.js /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ngAutocomplete", 3 | "version": "1.0.0", 4 | "main": "src/ngAutocomplete.js", 5 | "dependencies": { 6 | "angular": ">=1.2.0" 7 | } 8 | } -------------------------------------------------------------------------------- /examples/advanced.css: -------------------------------------------------------------------------------- 1 | #form { 2 | 3 | margin-left: 100px; 4 | width: 500px 5 | } 6 | 7 | .indent { 8 | 9 | margin-left: 50px; 10 | } 11 | 12 | .move-down { 13 | margin-top: 100px; 14 | } -------------------------------------------------------------------------------- /examples/advanced.js: -------------------------------------------------------------------------------- 1 | angular.module( "Test", ['ngAutocomplete']) 2 | .controller("TestCtrl",function ($scope) { 3 | 4 | $scope.result = '' 5 | // $scope.details = '' 6 | $scope.options = {}; 7 | 8 | $scope.form = { 9 | type: 'geocode', 10 | bounds: {SWLat: 49, SWLng: -97, NELat: 50, NELng: -96}, 11 | country: 'ca', 12 | typesEnabled: false, 13 | boundsEnabled: false, 14 | componentEnabled: false, 15 | watchEnter: true 16 | } 17 | 18 | //watch form for changes 19 | $scope.watchForm = function () { 20 | return $scope.form 21 | }; 22 | $scope.$watch($scope.watchForm, function () { 23 | $scope.checkForm() 24 | }, true); 25 | 26 | 27 | //set options from form selections 28 | $scope.checkForm = function() { 29 | 30 | $scope.options = {}; 31 | 32 | $scope.options.watchEnter = $scope.form.watchEnter 33 | 34 | if ($scope.form.typesEnabled) { 35 | $scope.options.types = $scope.form.type 36 | } 37 | if ($scope.form.boundsEnabled) { 38 | 39 | var SW = new google.maps.LatLng($scope.form.bounds.SWLat, $scope.form.bounds.SWLng) 40 | var NE = new google.maps.LatLng($scope.form.bounds.NELat, $scope.form.bounds.NELng) 41 | var bounds = new google.maps.LatLngBounds(SW, NE); 42 | $scope.options.bounds = bounds 43 | 44 | } 45 | if ($scope.form.componentEnabled) { 46 | $scope.options.country = $scope.form.country 47 | } 48 | }; 49 | 50 | }); 51 | 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ng-Autocomplete 2 | 3 | A simple directive for adding google places autocomplete to a textbox element. 4 | 5 | Updated to now use ng-model, should work much better in forms. Can now set an initial value using ng-model. Using the ng-model to set the textbox value does not trigger the autocomplete query. 6 | 7 | Tested with angularjs-1.2.4 8 | 9 | Uses optional directive parameters, so it won't work with <1.2. If people are interested I'll release a <1.2 version. 10 | 11 | ## Examples 12 | 13 | + [Example Plunkers - Simple Usage](http://plnkr.co/edit/GE34ojss9xMGm0024FvM?p=preview) 14 | 15 | + [Example Plunkers - Advanced Usage](http://plnkr.co/edit/GF3nM3XfYX9El2w11pGo?p=preview) 16 | 17 | ## Usage 18 | 19 | Include the required libraries 20 | ```html 21 | 22 | ``` 23 | 24 | Declare a dependency on the `ngAutocomplete` module 25 | ``` javascript 26 | var app = angular.module('myModule', ['ngAutocomplete']); 27 | ``` 28 | 29 | Add the directive to a textbox 30 | 31 | ``` javascript 32 | 33 | ``` 34 | 35 | ## Documentation 36 | 37 | + ng-model - autocomplete textbox value 38 | 39 | + details - more detailed autocomplete result, includes address parts, latlng, etc. (Optional) 40 | 41 | + options - configuration for the autocomplete (Optional) 42 | 43 | + types: type, String, values can be 'geocode', 'establishment', '(regions)', or '(cities)' 44 | + bounds: bounds, Google maps LatLngBounds Object, biases results to bounds, but may return results outside these bounds 45 | + country: country String, ISO 3166-1 Alpha-2 compatible country code. examples; 'ca', 'us', 'gb' 46 | + watchEnter: Boolean, true; on Enter select top autocomplete result. false(default); enter ends autocomplete 47 | 48 | example: 49 | ``` javascript 50 | options = { 51 | types: '(cities)', 52 | country: 'ca' 53 | } 54 | ``` 55 | 56 | google places autocomplete info: https://developers.google.com/maps/documentation/javascript/places 57 | 58 | ## Author 59 | 60 | **Will Palahnuk** (http://github.com/wpalahnuk) 61 | 62 | ## Credits 63 | 64 | google places autocomplete https://developers.google.com/maps/documentation/javascript/places 65 | 66 | ## Copyright and license 67 | 68 | The MIT License 69 | 70 | Copyright (c) 2014 Will Palahnuk 71 | 72 | Permission is hereby granted, free of charge, to any person obtaining a copy 73 | of this software and associated documentation files (the "Software"), to deal 74 | in the Software without restriction, including without limitation the rights 75 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 76 | copies of the Software, and to permit persons to whom the Software is 77 | furnished to do so, subject to the following conditions: 78 | 79 | The above copyright notice and this permission notice shall be included in 80 | all copies or substantial portions of the Software. 81 | 82 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 83 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 84 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 85 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 86 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 87 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 88 | THE SOFTWARE. 89 | -------------------------------------------------------------------------------- /examples/advanced.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |