0

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

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.