【问题标题】:Angular.js - Clear Text box when Google Autocomplete event fires?Angular.js - Google自动完成事件触发时清除文本框?
【发布时间】:2016-05-04 12:54:30
【问题描述】:

我想在谷歌地图自动完成事件触发时清除文本框的值。我是 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  

        });

【问题讨论】:

  • 有什么问题?
  • 输入框值没有变空。从谷歌自动完成选择一个城市后,我希望输入框为空白。 @AnikIslamAbhi

标签: javascript angularjs input autocomplete


【解决方案1】:

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

喜欢这个

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

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 2018-10-08
    相关资源
    最近更新 更多