I am using googlePlace api in angularJs and I want to change type of places dynamically as needed. Like I use controllers to bind the values in view part using $scope but it\'s
I found a different way to solve this problem. You don't need to extra just pass the types:[] as an argument in 'nearBySearch' function
$scope.data = ngGPlacesAPI.nearbySearch({latitude:ll.lat(), longitude:ll.lng(), types:[$scope.business.selected.businessType]}).then(
function(data){
$scope.person=data;
console.log(data);
return data;
});
"$scope.business.selected.businessType" is bindable dynamically from view, that's it.
You could have those set of default values as an constant, so that you could get those value inside config phase directly, as angular constant
s are accessible over there & in all other component of angular like controller
, factory
, directive
, etc just by injecting dependency of it.
Constant
app.constant('ngGPlacesDefaults', {
radius:1000000,
types:['electronics_store','bakery','bank','beauty_salon','bicycle_store','book_store','cafe','car_dealer','car_wash','car_repair','clothing_store','dentist','department_store'],
nearbySearchKeys: ['name','geometry', 'reference'],
placeDetailsKeys: ['name','formatted_address', 'formatted_phone_number',
'reference', 'website', 'geometry', 'email'],
});
})
Config
app.config(function(ngGPlacesAPIProvider, ngGPlacesDefaults){
ngGPlacesAPIProvider.setDefaults(ngGPlacesDefaults);
});
Whenever you wanted to change the value of ngGPlacesDefaults
configuration, you can have handle to those value by injecting ngGPlacesDefaults
dependency
app.controller('myController', function($scope, ngGPlacesDefaults){
//other code here
ngGPlacesDefaults.types = ["some", "different", "values"]; //you could change value like this
})