Jacob
Jacob

Reputation: 14731

Autocomplete using AngularJS and Restangular

I am trying to add autocomplete using angularJS and restangular.

http://plnkr.co/edit/Ud0c34afYZvHJ6ZQQX9N?p=preview

I am not sure how to add the following in order to make autocomplete work. Could someone suggest how to make this work

angular.module('emps', ['restangular']).directive('autoComplete', function($timeout) {
    return function($scope, iElement, iAttrs) {
            iElement.autocomplete({
                source: $scope[iAttrs.uiItems],
                select: function() {
                    $timeout(function() {
                      iElement.trigger('input');
                    }, 0);
                }
            });
    };
});

Upvotes: 0

Views: 584

Answers (1)

Macobo
Macobo

Reputation: 75

While there's not alot of info about what you need this for, I think this could be best solved without a separate directive, using the html5 tag.

Using this requires modifying the existing index.html to contain the following.

<div ng-controller="AutoCtrls">
    <input list="names" ng-model="selected">
    <datalist id="names">
        <option value="{{name}}" ng-repeat="name in names"></option>
    </datalist>
     selected = {{selected}}
</div>

For reference, the original code in index.html was

 <div ng-controller='AutoCtrls'>
    <input auto-complete ui-items="names" ng-model="selected">
     selected = {{selected}}
</div>

Upvotes: 1

Related Questions