【问题标题】:ng-model and value not working for input from google autocomplete formsng-model 和 value 不适用于来自谷歌自动完成表单的输入
【发布时间】:2015-04-05 21:59:47
【问题描述】:

我正在尝试从谷歌自动完成表单中选择值并将它们分配给输入。在我给他们 ng-model 之前,这非常有效,此时输入变为空白。我已经阅读了in this thread,我需要在控制器中分配值,而不是像我目前所做的那样分配 html。

这里是完整代码:http://plnkr.co/edit/qy9nNj4QM3J1S95ruBGh?p=preview

这是我试图用来执行此操作的特定部分:

<input ng-model="focus" ng-change="chosenPlace=focus" details="chosenPlaceDetails" placeholder="" googleplace />

<input class="input-field" type="text" id="city-input" ng-model="formData.city" />

$scope.$watch("focus", function(newVal){
   $scope.formData.city = $scope.chosenPlaceDetails.address_components[2].long_name;
})

但我仍然没有得到任何结果。我做错了什么?

【问题讨论】:

    标签: angularjs google-maps input


    【解决方案1】:

    首先安装 Places 自动完成 min.js 文件并将其包含在您的指令中。如 sn-p 所示。

    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
    <script src="../bower_components/angular/angular.min.js"></script>
    <script src="../ngPlacesAutocomplete.min.js"></script>
    <script src="app.js"></script>

    它必须在 Google api 之后但在 app.js 之前。

    参考这个GitHub example了解详细的实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-08
      • 2016-01-21
      • 2021-08-02
      • 2017-03-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多