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'.

Anonymous
  • 181
  • 11
  • You can not change `constants`, for your purpose use `values` or `factory` – Kulbhushan Singh Nov 10 '15 at 03:31
  • http://stackoverflow.com/questions/33579783/make-change-inside-app-config-in-angularjs/33579811?noredirect=1#comment54937189_33579811 Some one has suggested me that !! – Anonymous Nov 10 '15 at 03: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 !! – Anonymous Nov 10 '15 at 03:44
  • @Kulbhushan http://stackoverflow.com/questions/13035568/angular-js-value-not-injected-in-config – Anonymous Nov 10 '15 at 03: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 – Kulbhushan Singh Nov 10 '15 at 03:51
  • @Kulbhushan Can't I use factory ? – Anonymous Nov 10 '15 at 04:05
  • factory can't be injected in config, but `provider` can be injected. http://stackoverflow.com/questions/15286588/how-to-inject-dependency-into-module-configconfigfn-in-angular#answer-17846807. and factory is nothing but wrapper on top of provider, so you can use provider easily instead of factory – Kulbhushan Singh Nov 10 '15 at 04:11

0 Answers0