5
我想讓谷歌地方自動填充角js工作。這裏是jsfiddle - 模型在'place_change'事件後沒有得到更新。它正在更新輸入的更改。谷歌地方自動填充角js
下面是HTML代碼 - HTML
<body ng-app="mapApp">
<div ng-controller="MapController">
<input id="from" type="text" ng-model="user.from" placeholder="Type Address" class="ng-pristine ng-valid" autocomplete="off">
<input type="hidden" ng-model="user.fromLat">
<input type="hidden" ng-model="user.fromLng">
<p>{{user.from}} <br> {{'Latitude : ' + user.fromLat + ', Longitutde : ' + user.fromLng}}</p>
</div>
</body>
Java腳本
var mapApp = angular.module('mapApp', []);
mapApp.controller('MapController', function ($scope) {
$scope.user = {'from': '', 'fromLat': '', 'fromLng' : ''};
var options = {
componentRestrictions: {country: "in"}
};
var inputFrom = document.getElementById('from');
var autocompleteFrom = new google.maps.places.Autocomplete(inputFrom, options);
google.maps.event.addListener(autocompleteFrom, 'place_changed', function() {
var place = autocompleteFrom.getPlace();
$scope.user.fromLat = place.geometry.location.lat();
$scope.user.fromLng = place.geometry.location.lng();
$scope.user.from = place.formatted_address;
});
});
您的jsfiddle鏈接似乎並不奏效 – rob
更新的jsfiddle - http://jsfiddle.net/punchouty/cTD2a/6/ – Puja
'VAR inputFrom =的document.getElementById( '從'); '反對控制器最佳實踐中的角度不操縱,不是嗎?我們怎麼能用一個指令來實現這個? – sgimeno