Algolia自动完成传递选项

时间:2017-09-20 18:07:19

标签: algolia

使用角度库时如何传递选项对象?

示例从文档中清除,但与jquery示例不同,在初始化传入对象时,没有自动完成对象可供访问。

相反,它使用$scope.$on。你可以在哪里传递{ debug: true }

<script src="https://cdn.jsdelivr.net/algoliasearch/3/algoliasearch.angular.min.js"></script>
<script src="https://cdn.jsdelivr.net/autocomplete.js/0/autocomplete.angular.min.js"></script>
<script>
  angular.module('myApp', ['algoliasearch', 'algolia.autocomplete'])
    .controller('yourController', ['$scope', 'algolia', function($scope, algolia) {
      var client = algolia.Client('YourApplicationID', 'YourSearchOnlyAPIKey');
      var index = client.initIndex('YourIndex');

      $scope.getDatasets = function() {
        return {
          source: algolia.sources.hits(index, { hitsPerPage: 5 }),
          displayKey: 'my_attribute',
          templates: {
            suggestion: function(suggestion) {
              return suggestion._highlightResult.my_attribute.value;
            }
          }
        };
      };

      $scope.$on('autocomplete:selected', function(event, suggestion, dataset) {
        console.log(suggestion, dataset);
      });
    }]);
</script>

1 个答案:

答案 0 :(得分:1)

您可以传递aa-options,如下所述:

&#13;
&#13;
<input type="search" id="aa-search-input" class="aa-input-search" placeholder="Search for players or teams..." name="search"
    autocomplete aa-datasets="getDatasets()" aa-options="{hint: false}" />
&#13;
&#13;
&#13;