2014-07-08 39 views
5

Google yerlerinin otomatik tamamlama çalışmasını açısal js ile yapmaya çalışıyorum. İşte jsfiddle - Model'place_change 'olayından sonra güncellenmiyor. Giriş değişikliğinde güncellenmektedir. HTMLGoogle, açısal js ile otomatik tamamlama yerleştirir

<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 Script

Bunu DOM güncellemek için ne zaman bilmesi için place_change olay kovuluyor zaman açısal söylememe gerek
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; 
    }); 
}); 
+0

sizin jsFiddle bağlantı çalışıyor gibi görünmüyor – rob

+0

Güncellemeler JsFiddle - http://jsfiddle.net/punchouty/cTD2a/6/ – Puja

+0

'var inputFrom = document.getElementById ('den'); 'Angular'e karşı kontrolörlerin en iyi uygulamalarından dom manipülasyonu yok, değil mi? Bunu bir direktifle nasıl sağlayabiliriz? – sgimeno

cevap

5

- Aşağıda

html kodudur. Bunu $scope.$apply() numaralı telefonu arayarak yapabilirsiniz. örneğin:

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; 
     $scope.$apply(); 
    }); 
+0

Teşekkürler rob. İşe yaradı :) – Puja