Search code examples
angularjsng-tags-input

ng-tags-input autocomplete should generate tags through static array of objects


I am using ng-tags-input in AngularJS 1 for list of countries. I don't want to use the $http.get() for getting the tags. I have a static array of objects that I want to utilize in the tags.


Solution

  • Use the promise angular service in your load function:

    $q(function (resolve, reject) {
       resolve($scope.myArray);
    }
    

    This:

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

    Would be:

    $scope.loadTags = function () {
        return $q(function (resolve, reject) {
           resolve($scope.myArray);
        };
    };
    

    $q creates a promise and your plugin wants that.

    Don't forget to include $q in your dependencies.