algolia-multi-dropdown
v1.0.1
Published
AlgoliaSearchManager is a framework-agnostic TypeScript library that simplifies managing multiple Algolia search dropdowns or search components on a single page. Each instance can have its own plugins, allowing you to extend functionality with features su
Downloads
24
Maintainers
Readme
const manager = new AlgoliaSearchManager('YourAppID', 'YourSearchOnlyAPIKey');
@Component({
selector: 'app-product-search',
template: <input (input)="onSearch($event.target.value)" placeholder="Search products">
<ul>
<li *ngFor="let hit of results">{{ hit.name }}</li>
</ul>
,
})
export class ProductSearchComponent implements OnInit {
results: any[] = [];
private instanceId = 'productSearch';
constructor(private algoliaSearchService: AlgoliaSearchService) {}
ngOnInit() { this.algoliaSearchService.manager.addInstance({ id: this.instanceId, indexName: 'products', searchTerm: '', onResults: (res) => { this.results = res.results[0].hits; }, }); }
onSearch(value: string) { this.algoliaSearchService.manager.updateSearchTerm(this.instanceId, value); }
ngOnDestroy() { this.algoliaSearchService.manager.removeInstance(this.instanceId); } }
