@@ -5,7 +5,7 @@ import { APIResponse } from '../entity/APIResponse';
55import { Item } from '../entity/Item' ;
66import { environment } from '../environments/environment' ;
77import { HttpParams } from "@angular/common/http" ;
8- import { FormControl } from '@angular/forms' ;
8+ import { FormControl , FormGroup , FormBuilder } from '@angular/forms' ;
99import { MediaMatcher } from '@angular/cdk/layout' ;
1010import { getListeners } from '@angular/core/src/render3/discovery_utils' ;
1111
@@ -17,6 +17,8 @@ import { getListeners } from '@angular/core/src/render3/discovery_utils';
1717export class AppComponent {
1818 mode = 'determinate' ;
1919
20+ searchForm : FormGroup ;
21+
2022 // for search
2123 placeholder : string = 'New Items' ;
2224 allItems : string [ ] = [ 'Apple' , 'Lemon' , 'Lime' , 'Orange' , 'Strawberry' ] ;
@@ -58,10 +60,14 @@ export class AppComponent {
5860
5961 private mobileQueryListener : ( ) => void ;
6062
61- constructor ( private httpService : HttpService , changeDetectorRef : ChangeDetectorRef , media : MediaMatcher ) {
63+ constructor ( private httpService : HttpService , changeDetectorRef : ChangeDetectorRef , media : MediaMatcher , formBuilder : FormBuilder ) {
6264 this . mobileQuery = media . matchMedia ( '(max-width: 768px)' ) ;
6365 this . mobileQueryListener = ( ) => changeDetectorRef . detectChanges ( ) ;
6466 this . mobileQuery . addListener ( this . mobileQueryListener ) ;
67+ this . searchForm = formBuilder . group ( {
68+ query : '' ,
69+ 'company-name' : ''
70+ } ) ;
6571 }
6672
6773 ngOnInit ( ) : void {
@@ -88,14 +94,15 @@ export class AppComponent {
8894 this . mode = 'determinate' ;
8995 }
9096
91- getList ( page : any , size : any , orderBy ?: string , order ?: string , text ?: string ) {
97+ getList ( page : any , size : any , orderBy ?: string , order ?: string , formValue ?: any ) {
9298 this . startProgress ( ) ;
9399 const params = new HttpParams ( )
94100 . set ( 'page' , page )
95101 . set ( 'size' , size )
96102 . set ( 'orderBy' , orderBy || this . defaultSoredColumn )
97103 . set ( 'direction' , order || this . sortedAsc )
98- . set ( 'query' , text || '' ) ;
104+ . set ( 'query' , formValue && formValue . query || '' )
105+ . set ( 'company-name' , formValue && formValue [ 'company-name' ] ) ;
99106 this . httpService
100107 . get < APIResponse < Item > > ( environment . getAll , params )
101108 . subscribe ( ( response : any ) => {
@@ -124,11 +131,11 @@ export class AppComponent {
124131 }
125132 this . sortedColumnKey = column . key ;
126133 this . sortedColumn = column . value ;
127- this . getList ( 1 , this . pageSize , this . sortedColumn , this . sortedOrder ) ;
134+ this . getList ( 1 , this . pageSize , this . sortedColumn , this . sortedOrder , this . searchForm . value ) ;
128135 }
129136
130- search ( text : string ) {
131- this . getList ( 1 , this . pageSize , this . sortedColumn , this . sortedOrder , text ) ;
137+ search ( ) {
138+ this . getList ( 1 , this . pageSize , this . sortedColumn , this . sortedOrder , this . searchForm . value ) ;
132139 }
133140
134141}
0 commit comments