-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsearch.component.ts
More file actions
63 lines (56 loc) · 1.48 KB
/
search.component.ts
File metadata and controls
63 lines (56 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {Component} from "@angular/core";
import {ContactService} from "../services/contact.service";
import {
FormGroup,
FormControl
} from '@angular/forms';
@Component({
selector: 'search',
template: `
<form class="navbar-form navbar-left" [formGroup]="myform">
<div class="form-group">
<input type="text"
class="form-control"
formControlName="search"
placeholder="Search name..."/>
</div>
<div class="form-group">
<select class="form-control"
formControlName="sorting">
<option value="name">Name</option>
<option value="email">Email</option>
</select>
</div>
<div class="form-group">
<select class="form-control"
formControlName="ordering">
<option value="ASC">ASC</option>
<option value="DESC">DESC</option>
</select>
</div>
</form>
`
})
export class SearchComponent {
private myform: FormGroup;
constructor(private contacts: ContactService) {
this.myform = new FormGroup({
search: new FormControl(),
sorting: new FormControl('name'),
ordering: new FormControl('ASC')
});
}
ngOnInit() {
this.myform
.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.do(console.log)
.subscribe(({sorting, ordering, search}) => {
this.contacts.sorting = sorting;
this.contacts.ordering = ordering;
this.contacts.search = search;
this.contacts.doSearch();
});
}
}