AngularJS自定义指令打破了UI Bootstrap模态窗口

时间:2014-07-24 03:20:19

标签: javascript jquery angularjs angular-ui-bootstrap modal-window

我无法获得自定义指令(自动完成谷歌地方的指令)在ui引导模式窗口内正常工作。它在窗外完美运行。如果我把它放在模态体div中,没有任何建议出现。如果我把它放在身体和页脚div之间,它看起来很时髦。

我相信this issue是相关的,但无法弄清楚究竟如何:

我的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);
      }
    };
  });

以下是相关的plunker

非常感谢任何帮助或指导。我在这个问题上花了3天时间。修复此问题也可以帮助我使用另一个我想要使用的指令。谢谢!

1 个答案:

答案 0 :(得分:3)

好的victorsoto有正确的解决方案。

我将此添加到我的style.css中,它现在运行正常!

.pac-container {
z-index: 99999999;
}