Search code examples
javascriptangularjsangular-promiseng-tags-input

Error: promise is undefined


I am using angularjs to create a tag list input.
When I type more than 3 characters in tag list control the following error is shown in browser console.

AngularJS v1.2.23
ngTagsInput v2.1.0

Error: promise is undefined
SuggestionList/self.load/debouncedLoadId

HTML:

<tags-input ng-model="tags" display-property="Tag_Title" placeholder="Add Tag">
<auto-complete source="loadItems($query)"></auto-complete>
</tags-input>

app.js:

$scope.loadTags = function(query) {
    return $http.get('getTags?query=' + query).then(function (response) {
        return response.data;
    });
}

Solution

  • Bug fixed. In my HTML code the function name was "loadItems" but in app.js the function was named "loadTags".
    The complete solution is:

    HTML

    <tags-input ng-model="myTags" display-property="Tag_Title" placeholder="Add Tag">
        <auto-complete source="loadTags($query)"></auto-complete>
    </tags-input>
    

    app.js

    $scope.myTags = [];
    
    $scope.loadTags = function(query) {
        return $http.get('getTags?query=' + query)
            .then(function (response) {
                return response.data;
        });
    }
    

    php
    For server-side I have used Laravel framework

    public function getTags() 
    {
        $query = Input::get('query');
    
        return Tag::where('Tag_Title', 'LIKE', $query.'%')->get();
    }