0

I want to set the value of table cell to the address returned by the geocode api.

{{addr}}

the controller method written by me is as follows.

this.getAddress = function(lat,lng) {
        console.log('x.lat ' + lat + ' x.lng ' + lng);
        var p = new Promise(function(resolve,reject){
            var address;
            var geocoder = new google.maps.Geocoder;
            geocoder.geocode({'location': {lat: parseFloat(lat), lng: parseFloat(lng)}}, function(results, status) {
                if (status === 'OK') {
                    if (results[0]) {
                        resolve(results[0].formatted_address);
                    } else {
                        resolve('No results found');
                    }
                } else {
                    reject('Geocoder failed due to: ' + status);
                }
            });
        }).then(function(v){
            console.log('Resolved - Geo coder address ' + v);
            $scope.addr = v;
        }).catch(function(v){
            console.log('Catch - Geo coder address ' + v);
        });
    };

But the value of addr is not getting changed though i am getting the address information in the controller method.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Satya Narayana
  • 454
  • 6
  • 20
  • Try it with `$q` promise, maybe it should work (not sure though) – Alon Eitan Mar 17 '17 at 11:21
  • Have you tried to call ```$scope.$apply();``` after setting ```$scope.addr = v;``` ? – Dario Mar 17 '17 at 11:45
  • I tried $scope.apply but it is not working – Satya Narayana Mar 20 '17 at 07:02
  • Getting, Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! after changing the line new Promise(function(resolve,reject){..} to $q(function(resolve,reject){...}) I changed angular.module('myapp').controller('panel1controller', function($scope,$http,$window,$interval) {...}) to angular.module('myapp').controller('panel1controller', function($scope,$q,$http,$window,$interval) {...}) – Satya Narayana Mar 20 '17 at 07:16

0 Answers0