Skip to content

Commit dc99a03

Browse files
committed
places-auto-complete filter by country dynamically
watch 'component-restrictions' attribute to trigger country's filter dynamically
1 parent 5fc84a0 commit dc99a03

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

directives/places-auto-complete.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @example
1414
* Example:
1515
* <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
16-
* <input places-auto-complete types="['geocode']" on-place-changed="myCallback(place)" />
16+
* <input places-auto-complete types="['geocode']" on-place-changed="myCallback(place)" component-restrictions="{country:'au'}"/>
1717
*/
1818
/* global google */
1919
(function() {
@@ -48,8 +48,14 @@
4848
autocomplete.setTypes(optionValue);
4949
}
5050
});
51+
52+
attrs.$observe('componentRestrictions', function (val) {
53+
if (val) {
54+
autocomplete.setComponentRestrictions(scope.$eval(val));
55+
}
56+
});
5157
};
52-
58+
5359
return {
5460
restrict: 'A',
5561
require: '?ngModel',
@@ -59,5 +65,4 @@
5965

6066
placesAutoComplete.$inject = ['Attr2MapOptions', '$timeout'];
6167
angular.module('ngMap').directive('placesAutoComplete', placesAutoComplete);
62-
6368
})();

0 commit comments

Comments
 (0)