forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.component.ts
More file actions
37 lines (34 loc) · 917 Bytes
/
search.component.ts
File metadata and controls
37 lines (34 loc) · 917 Bytes
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
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Output,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
@Component({
selector: 'app-search',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [MatFormFieldModule, MatInputModule, FormsModule],
template: `
<mat-form-field class="w-4/5" cd-flash>
<input
placeholder="Add one member to the list"
matInput
type="text"
[(ngModel)]="label"
(keydown)="handleKey($event)" />
</mat-form-field>
`,
})
export class SearchComponent {
@Output() newName = new EventEmitter<string>();
label = '';
handleKey(event: KeyboardEvent) {
if (event.key === 'Enter') {
this.newName.emit(this.label);
this.label = '';
}
}
}