2016-12-09 19 views
0

需要幫助首先加載靜態標籤並同時創建後端API,以獲取建議列表作爲自動完成loadTags函數的一部分,因爲它僅適用於函數的第一次返回,所以我可以爲後端點擊並返回列表或者我可以返回靜態列表;如何在Angular js的ngTagsInput中加載靜態和Api響應標籤?

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; 
    });