File tree Expand file tree Collapse file tree
angular-instantsearch/using-instantsearch/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 type ="checkbox "
77 [value] ="brand.value "
88 [checked] ="brand.isRefined "
9- (change) ="refineBrands(brand.value) "
9+ (change) ="refineBrands! (brand.value) "
1010 />
1111 < span >
1212 {{ brand.label }}
2323 @for (querySuggestion of querySuggestions; track querySuggestion) {
2424 < li >
2525 < a
26- (click) ="$event.preventDefault(); refineQuery(querySuggestion) "
26+ (click) ="$event.preventDefault(); refineQuery! (querySuggestion) "
2727 href ="# "
2828 >
2929 {{ querySuggestion }}
Original file line number Diff line number Diff line change @@ -32,9 +32,9 @@ export class FacetsComponent {
3232 } ) ( { } ) ,
3333 index ( { indexName : 'instant_search_demo_query_suggestions' } ) . addWidgets ( [
3434 connectHits ( ( { hits } ) => {
35- this . querySuggestions = (
36- hits as Array < Hit < BaseHit & { query : string } > >
37- ) . map ( ( hit ) => hit . query ) ;
35+ this . querySuggestions = ( hits as Array < Hit < { query : string } > > ) . map (
36+ ( hit ) => hit . query
37+ ) ;
3838 } ) ( { } ) ,
3939 ] ) ,
4040 ] ) ;
Original file line number Diff line number Diff line change 11< main class ="main " style ="display: flex ">
22 < app-facets />
33 < div >
4- < input type ="text " [value] ="query " (input) ="search ($event.target.value ) " />
4+ < input type ="text " [value] ="query " (input) ="handleInput ($event) " />
55 < ul >
6- @for (hit of hits; track hit.objectId ) {
6+ @for (hit of hits; track hit.objectID ) {
77 < li >
8- < a routerLink ="/product ">
8+ < a routerLink ="/product " [queryParams] =" { objectID: hit.objectID } " >
99 {{ hit.name }}
1010 </ a >
1111 </ li >
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { Component } from '@angular/core';
22import { RouterLink , RouterLinkActive } from '@angular/router' ;
33import { InstantSearchService } from '../instant-search.service' ;
44import { connectHits , connectSearchBox } from 'instantsearch.js/es/connectors' ;
5- import { BaseHit } from 'instantsearch.js' ;
5+ import { Hit } from 'instantsearch.js' ;
66import { FacetsComponent } from '../facets/facets.component' ;
77
88@Component ( {
@@ -12,7 +12,7 @@ import { FacetsComponent } from '../facets/facets.component';
1212 templateUrl : './home.component.html' ,
1313} )
1414export class HomeComponent {
15- public hits ?: BaseHit [ ] ;
15+ public hits ?: Hit [ ] ;
1616 public query ?: string ;
1717 public search ?: ( value : string ) => void ;
1818
@@ -30,7 +30,17 @@ export class HomeComponent {
3030 ] ) ;
3131 }
3232
33+ handleInput ( event : Event ) {
34+ if ( event . target instanceof HTMLInputElement ) {
35+ this . search ! ( event . target . value ) ;
36+ }
37+ }
38+
3339 ngAfterContentInit ( ) {
3440 this . InstantSearchService . start ( ) ;
3541 }
42+
43+ ngOnDestroy ( ) {
44+ this . InstantSearchService . dispose ( ) ;
45+ }
3646}
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export class InstantSearchService {
3232 }
3333 return window . location ;
3434 } ,
35+ cleanUrlOnDispose : false ,
3536 } ) ,
3637 } ,
3738 } ) ;
@@ -41,6 +42,10 @@ export class InstantSearchService {
4142 this . instantSearchInstance . start ( ) ;
4243 }
4344
45+ dispose ( ) {
46+ this . instantSearchInstance . dispose ( ) ;
47+ }
48+
4449 addWidgets ( widgets : Array < Widget | IndexWidget > ) {
4550 this . instantSearchInstance . addWidgets ( widgets ) ;
4651 }
You can’t perform that action at this time.
0 commit comments