$http issue - Values can't be returned before a promise is resolved in md-autocomplete Angular Material

前端 未结 4 1938
别那么骄傲
别那么骄傲 2021-01-03 06:06

I\'m using Angular Material md-autocomplete in my project. In that I\'m getting the suggest listing from the Service Host via ajax call using $http

4条回答
  •  有刺的猬
    2021-01-03 06:53

    I struggled with this as well for a bit. Basically you should actually be returning a promise that returns the content.

    This is my "search" function

    $scope.searchData = function (searchTxt) {
            return $http.get('/TestSearch', { params: { searchStr: searchTxt } })
                .then(function(response) {
    
                    return response.data;
                });
        };
    

    Also I'm not sure what version of angular you're running but I think .success was deprecated.

    And here is my md-autocomplete as well

    
        {{item}}
    
    

    EDIT1: Sorry original JS was in TypeScript. Fixing that now

提交回复
热议问题