我想在谷歌地图自动完成事件触发时清除文本框值。我是 AngularJS 的新手,所以遇到的困难很少。有人可以帮忙吗?
HTML -
<input ng-model="deployText" id="search_execute" class="form-control" type="text" placeholder="Enter locations">
Controller 函数内的 JS 代码 -
var autocomplete = new google.maps.places.Autocomplete($("#search_execute")[0], {types: ['(cities)']});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
angular.element(document.getElementById('execute_place')).append("<div style='float:left'>"+place.address_components[0].long_name+"</div>");
$scope.execute.push({latitude:place.geometry.location.lat(), longitude:place.geometry.location.lng()});
$scope.deployText = ""; //Here I want to clear the text
});
最佳答案
您必须对非 Angular 组件使用$scope.$apply()
才能进行更改
像这样
$scope.deployText = ""; //Here I want to clear the text
$scope.$apply();
关于javascript - Angular.js - Google 自动完成事件触发时清除文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35039620/