Material: autocomplete not working without cache with $resource response

Created on 4 Feb 2016  路  1Comment  路  Source: angular/material

So it's basically what the question says, i have a function that returns a response from $resource which fetches from server.

var user = $resource(apiHost + '/users/:action/:query', {query: '@query'}, {
    search: {
        method: 'GET',
        isArray: true,
        params: {
            action: 'search',
            query: '@query'
        }
    }
});
self.search = function(name){
    return user.search({query: name}, function(result){
        return result;
    });
}

this is a service, i say this just to clear some confusions

now, in controller, where i am making the call to service function

$scope.searchUser = function(name){
    return userService.search(name);
};

it seems simple, but i have to admit i don't find any problem this far.

now in html where autocomplete is rendered

<md-autocomplete md-no-cache="true" md-search-text="searchText" md-selected-item="selectedItem" md-items="user in searchUser(searchText)" md-item-text="user.name">
    <span md-highlight-text="searchText">{{user.name}}</span>
</md-autocomplete>

now from here. i am not sure if the problem comes from here. but when i type something in autocomplete, nothing shows.. and i have been making sure the server is getting the requests i need to make.

I have tried without the attribute md-no-cache and the effects are kind of different. When some text is entered. nothing is shown.. but when part of the text is deleted, the autocomplete shows the results.

Most helpful comment

i found the solution.. turns out, this was a problem with promises..

i had to make searchUser function to return a promise of the fetched data

$scope.searchUser = function(name){
    return userService.search(name).$promise;
};

>All comments

i found the solution.. turns out, this was a problem with promises..

i had to make searchUser function to return a promise of the fetched data

$scope.searchUser = function(name){
    return userService.search(name).$promise;
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikhildev picture nikhildev  路  3Comments

WebTechnolog picture WebTechnolog  路  3Comments

PeerInfinity picture PeerInfinity  路  3Comments

robertmesserle picture robertmesserle  路  3Comments

diogodomanski picture diogodomanski  路  3Comments