Javascript 使用google maps autocomplete时,ng模型仅在单击后更新输入

Javascript 使用google maps autocomplete时,ng模型仅在单击后更新输入,javascript,jquery,angularjs,google-maps,Javascript,Jquery,Angularjs,Google Maps,我从RESTAPI收到一个google地图位置id。然后,我使用google maps api获得如下位置对象: var geocoder = new google.maps.Geocoder; geocoder.geocode({ 'placeId': data.city }, function(results, status) { if (status === google.maps.GeocoderStatus

我从RESTAPI收到一个google地图位置id。然后,我使用google maps api获得如下位置对象:

var geocoder = new google.maps.Geocoder;
        geocoder.geocode({
            'placeId': data.city
        }, function(results, status) {
            if (status === google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                    $scope.place = results[0];
                } else {
                    window.alert('No results found');
                }
            } else {
                window.alert('Geocoder failed due to: ' + status);
            }
        });
<label><span>Stadt</span><input type="text" g-places-autocomplete ng-model="place.formatted_address" name="city" class="f-trans"/></label>
我在前端使用的范围变量中写入结果,如下所示:

var geocoder = new google.maps.Geocoder;
        geocoder.geocode({
            'placeId': data.city
        }, function(results, status) {
            if (status === google.maps.GeocoderStatus.OK) {
                if (results[0]) {
                    $scope.place = results[0];
                } else {
                    window.alert('No results found');
                }
            } else {
                window.alert('Geocoder failed due to: ' + status);
            }
        });
<label><span>Stadt</span><input type="text" g-places-autocomplete ng-model="place.formatted_address" name="city" class="f-trans"/></label>
statt

我正在使用来自github的kuhnza/angular google places autocomplete来实现自动完成功能。不知何故,现在我遇到了这样一个问题:当作用域变量由顶部的函数设置时,它不会更新输入。只有当我在输入字段内部和外部再次单击时,它才会得到更新,并且自动完成功能运行没有任何问题。它与我使用的“kuhnza/angular google places autocomplete”标记无关,因为如果我删除它,它仍然不起作用。

您正在angular之外更新模型。因此,在与angular交互之前,它不会意识到值已更新。最后,我检查了确保更新在角度摘要中的最简单方法是将其包装在
$timeout
(确保您也将其注入)