如何在Angular js中的ngTagsInput中加载静态和Api响应标记?

时间:2016-12-09 10:13:26

标签: javascript angularjs ng-tags-input

需要帮助首先加载静态标记并同时点击后端API以获取建议列表作为自动完成loadTags函数的一部分,因为它仅适用于函数的第一次返回,所以我要么能够命中后端并返回列表或我能够返回静态列表;

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

1 个答案:

答案 0 :(得分:0)

您可以这样做:

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

apiService.getBackendTags(query).then(function(response) {
      myLocalTags = _.values(_.merge(myLocalTags, response.data));
      $scope.autocompleteSuggestions = myLocalTags;
    });