角度.js - Google 自动完成事件触发时的清除文本框

Angular.js - Clear Text box when Google Autocomplete event fires?

本文关键字:清除 文本 事件 js Google 角度      更新时间:2023-09-26

我想在谷歌地图自动完成事件触发时清除文本框值。我是AngularJS的新手,所以没有什么困难。谁能帮忙?

.HTML-

<input ng-model="deployText" id="search_execute" class="form-control" type="text" placeholder="Enter locations">

控制器功能中的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  
        });

您必须对非角度组件使用 $scope.$apply() 才能进行更改

喜欢这个

$scope.deployText = "";  //Here I want to clear the text  
$scope.$apply();