2016-12-09 6 views
0

staticタグとヒットバックエンドAPIを同時にロードして、autocomplete loadTags関数の一部として提案リストを取得するのに役立つ必要があるので、関数の最初の戻り時にのみ機能するため、バックエンドでヒットしてリストを返すことができます。または静的リストを返すことができます。ngTagsInputに静的応答タグとApi応答タグの両方をAngular jsでロードするにはどうすればよいですか?

function loadTags(query) { 
    myLocalTags = _.merge(filteredBasicTags, filteredAdvTags); 

    apiService.getBackendTags(query).then(function(response) { 
     myLocalTags = _.values(_.merge(myLocalTags, response.data)); 
     return myLocalTags; 
    }); 
    //so either I am able to return the apiService Response or the myLocalTags Data for the autocomplete suggestions. 

    return myLocalTags; 
    } 

答えて

0

あなたはこのような何かを行うことができます。

$scope.autocompleteSuggestions = _.merge(filteredBasicTags, filteredAdvTags); 

apiService.getBackendTags(query).then(function(response) { 
     myLocalTags = _.values(_.merge(myLocalTags, response.data)); 
     $scope.autocompleteSuggestions = myLocalTags; 
    }); 
関連する問題