1

I defined a constant 'ngGPlacesDefaults' which sets default values of 'google place search' config file. But now I want to change the values of defaults dynamically i.e types:['airport'], types['backery'] etc as needed. And for this I injected the above constant inside my controller and tried to set defaults from inside my controller. But it's not working I mean It's not changing the values.

I am providing code for config file, constant and controller.

Any help would be much appreciated!!

map config code->

app.config(function(ngGPlacesAPIProvider, ngGPlacesDefaults){
	  ngGPlacesAPIProvider.setDefaults(ngGPlacesDefaults);
	});

app.constant code->

app.constant('ngGPlacesDefaults', {
    radius:1000000,
    types:['shoe_store'],
    nearbySearchKeys: ['name','geometry', 'reference'],
    placeDetailsKeys: ['name','formatted_address', 'formatted_phone_number',
        'reference', 'website', 'geometry', 'email']
  });

controller code ->

app.controller('scdfindCustomerCtrl',function($scope,ngGPlacesAPI,$http,ngGPlacesDefaults){

	  ngGPlacesDefaults.types = ["electronics_store"];
	
	$scope.getDetails = function(ref){
		$scope.details = ngGPlacesAPI.placeDetails({reference:ref}).then(
			    function (data) {
			    	$scope.det=data;
			      console.log(data);
			      return data;
			    });
	}
	
	$scope.positions = [{lat:37.7699298,lng:-122.4469157}];
	
	$scope.addMarker = function(event) {
    var ll = event.latLng;
		
    $scope.positions.push({lat:ll.lat(), lng: ll.lng()});
  
	
	$scope.data = ngGPlacesAPI.nearbySearch({latitude:ll.lat(), longitude:ll.lng()}).then(
    function(data){
		$scope.person=data;
		console.log(data);
	  return data;
    });
}

....some more code... 
});

In current scenario I want this code to show the list of 'electronics_store' but It's showing list of 'shoe_store'.

7
  • You can not change constants, for your purpose use values or factory Commented Nov 10, 2015 at 3:31
  • stackoverflow.com/questions/33579783/… Some one has suggested me that !! Commented Nov 10, 2015 at 3:32
  • @Kulbhushan Can I inject value inside config file like I changed constant to value and run my app gain but this time it's showing errors !! Commented Nov 10, 2015 at 3:44
  • @Kulbhushan stackoverflow.com/questions/13035568/… Commented Nov 10, 2015 at 3:45
  • 1
    You are right, values can't be used in config, but it can be changed. I didn't knew your previous requirement. you can use provider I see that as only option Commented Nov 10, 2015 at 3:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.