馃帀 Try the public beta of the new docs site at algolia.com/doc-beta! 馃帀
UI libraries / Angular InstantSearch / Widgets

ais-query-rule-custom-data

Angular InstantSearch isn鈥檛 compatible with Angular鈥檚 Ivy view engine. We鈥檙e investigating how best to support this. For more information and to vote for Algolia鈥檚 support of Angular 16 and beyond, see the GitHub issue Algolia Support for Angular InstantSearch

Signature
<ais-query-rule-custom-data
  // Optional parameters
  [transformItems]="function"
></ais-query-rule-custom-data>
Import
1
2
3
4
5
6
7
8
import { NgAisQueryRuleCustomDataModule } from 'angular-instantsearch';

@NgModule({
  imports: [
    NgAisQueryRuleCustomDataModule,
  ],
})
export class AppModule {}

1. Follow additional steps in Optimize build size to ensure your code is correctly bundled.
2. This imports all the widgets, even the ones you don鈥檛 use. Read the Getting started guide for more information.

About this widget

The ais-query-rule-custom-data widget displays custom data from Rules.

You may want to use this widget to display banners or recommendations returned by Rules, and that match search parameters.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<ais-query-rule-custom-data>
  <ng-template let-items="items">
    <div *ngFor="let item of items">
      <div *ngIf="item.banner">
        <h2>{{ item.title }}</h2>
        <a [href]="item.link">
          <img
            [src]="item.banner"
            [alt]="item.title"
          />
        </a>
      </div>
    </div>
  </ng-template>
</ais-query-rule-custom-data>

Properties

Parameter Description
transformItems
type: function
Optional

Receives the items and is called before displaying them. Should return a new array with the same shape as the original array. Useful for transforming, removing, or reordering items.

In addition, the full results data is available, which includes all regular response parameters, as well as parameters from the helper (for example disjunctiveFacetsRefinements).

1
2
3
<ais-query-rule-custom-data
  [transformItems]="transformItems"
></ais-query-rule-custom-data>

Templates

Parameter Description
items
type: object[]

The items returned by the Rules.

The following example assumes a Rule returned this custom data.

1
2
3
4
5
{
  "title": "This is an image",
  "banner": "image.png",
  "link": "https://website.com/"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<ais-query-rule-custom-data>
  <ng-template let-items="items">
    <div *ngFor="let item of items">
      <div *ngIf="item.banner">
        <h2>{{ item.title }}</h2>
        <a [href]="item.link">
          <img
            [src]="item.banner"
            [alt]="item.title"
          />
        </a>
      </div>
    </div>
  </ng-template>
</ais-query-rule-custom-data>

HTML output

1
<div class="ais-QueryRuleCustomData"></div>
Did you find this page helpful?