2

UI ブートストラップ モーダル ウィンドウ内でカスタム ディレクティブ (Google Places をオートコンプリートするディレクティブ) を正しく動作させるのに問題があります。それは窓の外で完全に機能します。modal-body div 内に配置すると、提案は表示されません。body div と footer div の間に入れるとファンキーに見えます。

この問題は関連していると思いますが、正確にどのように把握することはできません:

私のindex.html:

<body>
    <div ng-controller="ModalDemoCtrl">
        <button class="btn btn-default" ng-click="open('lg')">Large modal</button>
        <div ng-show="selected">Selection from a modal: {{ selected }}</div>
    </div>
<-- this form works fine -->
<form id="form2" role="form">
    <div class="form-group move-down">
    <input type="text" id="Autocomplete2" class="form-control" ng-autocomplete="result1" details="details1" options="options1" />
    </div>
</form>
</body>

JS:

'use strict';
angular.module('myApp.directives', []).
.directive('ngAutocomplete', function($parse) {
    return {
        scope: {
        details: '=',
        ngAutocomplete: '=',
        options: '='
     },

        link: function(scope, element, attrs, model) {
            //options for autocomplete
            var opts;
            //convert options provided to opts
            var initOpts = function() {
            opts = {};
            if (scope.options) {
                if (scope.options.types) {
                    opts.types = [];
                    opts.types.push(scope.options.types)
                }
                if (scope.options.bounds) {
                    opts.bounds = scope.options.bounds
                }
                if (scope.options.country) {
                    opts.componentRestrictions = {
                    country: scope.options.country
                }
              }
          }
    };
        initOpts();

        //create new autocomplete
        //reinitializes on every change of the options provided
        var newAutocomplete = function() {
            scope.gPlace = new google.maps.places.Autocomplete(element[0], opts);
            google.maps.event.addListener(scope.gPlace, 'place_changed', function() {
            scope.$apply(function() {
                scope.details = scope.gPlace.getPlace();
                scope.ngAutocomplete = element.val();
             });
          })
        };
         newAutocomplete();

        //watch options provided to directive
        scope.watchOptions = function () {
          return scope.options
    };
        scope.$watch(scope.watchOptions, function () {
          initOpts();
          newAutocomplete();
          element[0].value = '';
          scope.ngAutocomplete = element.val();
        }, true);
      }
    };
  });

ここに関連するプランカーがあります

どんな助けや指導も大歓迎です。この問題に 3 日間を費やしました。これを修正すると、使用したい別のディレクティブにも役立ちます。ありがとう!

4

1 に答える 1

3

victorsoto には正しい解決策がありました。

これをstyle.cssに追加したところ、正常に動作するようになりました!

.pac-container {
z-index: 99999999;
}
于 2014-07-29T15:57:23.673 に答える