Created
September 27, 2014 23:08
-
-
Save abjerner/db1529f784a60dd1026e to your computer and use it in GitHub Desktop.
Example controller for a AngularJS property editor in Umbraco 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('umbraco').controller('GoogleAddressSearchController', ['$scope', '$http', function ($scope, $http) { | |
if (!$scope.model.address) $scope.model.address = ''; | |
$scope.address = $scope.model.address; | |
$scope.suggestions = []; | |
$scope.addressKeyDown = function () { | |
$http({ | |
url: 'http://maps.googleapis.com/maps/api/geocode/json', | |
params: { | |
address: $scope.address | |
} | |
}).success(function (res) { | |
$scope.suggestions = res.results; | |
}).error(function () { | |
alert('Something bad happened!!!'); | |
}); | |
}; | |
$scope.select = function (r) { | |
$scope.model.address = r.formatted_address; | |
$scope.model.latitude = r.geometry.location.lat; | |
$scope.model.longitude = r.geometry.location.lng; | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment