I'm currently using Angular with Angular Instant Search.
1 - Dynamically update the HTML config based on URL param change
- I have a split screen application. Folders on the left. Projects on the right.
- When clicking on a folder, the folder ID in the URL is modified
- My projects component subscribes to these changes and updates a local varaible for my folder ID
- I use this folder ID in my Angular Instant Search config.
Reading the change of folder id in the url
setUrlParams(){
this.activatedRoute.params.subscribe((urlParameters) => {
this.folder_id = urlParameters['folderId'];
this.setSearchConfig( this.folder_id);
});
}
Updating my Angular Instant Search config
setSearchConfig(folder_id){
this.configOption = {
apiKey: "apiKey",
appId: "appID",
indexName: "projects",
routing: false,
searchParameters: {
facetsRefinements: {
project_folder: [folder_id]
}
},
};
}
HTML
<ais-instantsearch [config]="configOption">
<ais-search-box placeholder='Search for products'></ais-search-box>
<ais-hits>
<ng-template let-hits="hits">
<div *ngFor="let hit of hits">
Hit {{hit.objectID}}: {{hit.project_title}}
</div>
</ng-template>
</ais-hits>
</ais-instantsearch>
On the initial load, this works great. However, when clicking on a folder and updating the ID, the correct ID is passed into the "setSearchConfig" function. But the HTML isn't updating unless I refresh the page.
Question How do I make the HTML dynamically update?