Ravindra Jha Ravindra Jha - 5 months ago 37
Javascript Question

Angularjs autocomplete

I am using a popup in angularjs with a form.I am using a auto-completer as-

portfolio.directive('auto', function($timeout) {
var names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];

return {
restrict : 'A',
require : 'ngModel',
link : function(scope, iElement, iAttrs) {
iElement.autocomplete({
source: names,
onSelect: function() {
$timeout(function() {
iElement.trigger('input');
}, 0);
}
});
}
};
});


it is working but the autocomplete box opens behind the popup.
can any one suggest the solution?

Answer

Try this out

Working Demo

Html

<div ng-app='MyModule'>
    <div ng-controller='DefaultCtrl'>
        <input auto  ng-model="selected">
        selected = {{selected}}
    </div>
</div>

script

function DefaultCtrl($scope) {

}

angular.module('MyModule', []).directive('auto', function($timeout) {
    var names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];

    return {
        restrict : 'A',
        require : 'ngModel',
        link : function(scope, iElement, iAttrs) {
            iElement.autocomplete({
                source: names,
                select: function() {
                    $timeout(function() {
                      iElement.trigger('input');
                    }, 0);
                }
            });
    }
    };
});
Comments