我无法让自定义指令(自动完成谷歌位置的指令)在 ui 引导模式窗口内正常工作。它在窗外完美运行。如果我将它放在 modal-body div 中,则不会出现任何建议。如果我把它放在正文和页脚 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);
}
};
});
这是相关的plunker
任何帮助或指导将不胜感激。我在这个问题上花了 3 天时间。解决这个问题也可以帮助我处理我想使用的另一个指令。谢谢!