javascript - 自动完成位置 angularjs 不适用于弹出窗口

标签 javascript jquery angularjs

In my application, I use google location autocomplete to suggest location when I enter some text. without popup then location autocomplete work fine but when I use location autocomplete on a popup then it not working. I use a directive

(function() {
'use strict';

angular
.module('crmApp')
.directive('googleplace', directiveFunction);
directiveFunction.$inject = ['$rootScope'];

function directiveFunction($rootScope) {
    return {
        require: '?ngModel',
        scope: {
            ngModel: '=',
            details: '=?'
        },
        link: function(scope, element, attrs, model) {
            var options = {
                types : ['geocode']
            };
            scope.gPlace = new google.maps.places.Autocomplete(element[0], options);

            google.maps.event.addListener(scope.gPlace, 'place_changed', function() {
                scope.$apply(function() {
                  scope.details = scope.gPlace.getPlace();
                  model.$setViewValue(element.val());
                  $rootScope.$broadcast('place_changed', scope.details);
              });
            });
        }
    };
}

})();

then I open popup but not working:

<input next-on-enter type="text"  googleplace ng-model="vm.origin" class="form-control" placeholder="Vui lòng nhập xuất xứ"  maxlength="255" name="origin"/>

Screen: google location autocomplete

Help me, please !!!

最佳答案

googleplace directive you write missing something to work. You need modify directive same as example in link: http://plnkr.co/edit/irQiP6waYf5kE6B4NCBe?p=preview

应用自动完成功能的输入更改为:

<input next-on-enter type="text" ng-autocomplete ng-model="vm.origin" options="autoCompleteOptions" details="autoCompleteDetails" class="form-control" placeholder="Vui lòng nhập xuất xứ"  maxlength="255" name="origin"/>

(原帖:https://github.com/angular-ui/bootstrap/issues/693)

关于javascript - 自动完成位置 angularjs 不适用于弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46317125/

相关文章:

javascript - 显示默认项目 (javascript)

javascript - 如何测试 JavaScript 对象是否是有序类型的对象

javascript - React 路由器在刷新后渲染组件

javascript - Textarea enter keypress 不工作,因为表单提交 enter prevention

JavaScript;如何在三位数字后设置点?

javascript - 使用 Jquery 将 Iframe 插入到类中

javascript - AngularJS:导航栏

angularjs - 带有 Angular js 链接的 Google 跟踪代码管理器

angularjs - 在 Spring Web 项目中集成 Angular JS 导致将项目永远发布到 Tomcat

javascript - 带 Subnav 的水平 CSS 菜单 - 设置事件选项卡