0

I am using ngTagsInput which has an auto-complete feature. It seems to be working very well. My problem is I want to know how to pass the query from source="loadTags(query)" into the directive, but query is always undefined. Query should simply be whatever text is typed in the search box.

Angular:

app.directive('tag', function($q) {
  return {
    restrict: 'E',
    templateUrl: 'tag.html',
    link: function (scope) {
       scope.tags = [
          { text: 'Tag1' },
          { text: 'Tag2' },
          { text: 'Tag3' }
        ];

        scope.loadTags = function(query) {
          console.log(query)
          var deferred = $q.defer();
          deferred.resolve([{ text: 'Tag9' },{ text: 'Tag10' }]);
          return deferred.promise;
        };
    }
  }
});

HTML:

<tags-input ng-model="tags">
  <auto-complete source="loadTags(query)"></auto-complete>
</tags-input>
<p>Model: {{tags}}</p>

My Plunker: http://plnkr.co/edit/3UuRok?p=info

1 Answer 1

2

This will fix it for you:

Change

<auto-complete source="loadTags(query)"></auto-complete>

To

<auto-complete source="loadTags($query)"></auto-complete>

See updated Plunker.

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.