I have been messing with this for 2 hours, can not find a solution. Below is the chrome dev tools output showing the logs.
(in order)
3 - undefined
1 - check
2 - A Google User
Why is the place variable in my html not being updated to 'A Google User'?
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', ['$scope', '$http', '$log',
function($scope, $http, $log) {
var request = {
placeId: 'ChIJX3piIfJ4j4ARXuQlqgn6LaA' //Walmart HQ
};
service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
$log.log('1 - check');
$log.log('2 - ' + place.reviews[0].author_name);
$scope.place = place.reviews[0].author_name;
});
$log.log('3 - ' + $scope.place);
}
]);
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Place details</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js'></script>
<script src="app.js"></script>
</head>
<body>
<div id="map"></div>
<div ng-controller='AppCtrl'>
{{ place }}
</div>
</div>
</body>
</html>