-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathaction.component.ts
More file actions
42 lines (39 loc) · 1.22 KB
/
action.component.ts
File metadata and controls
42 lines (39 loc) · 1.22 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
import {
ChangeDetectionStrategy,
Component,
inject,
signal,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { UserService } from './user.service';
@Component({
imports: [FormsModule],
selector: 'app-actions',
template: `
<form class="mx-auto max-w-sm">
<label for="actions" class="mb-2 block text-sm font-medium text-gray-900">
Choose an action
</label>
<select
name="actions"
[ngModel]="action"
(ngModelChange)="logMessage($event)"
id="actions"
class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500">
<option selected>Please select an action</option>
@for (action of actions; track $index) {
<option value="{{ action }}">{{ action }}</option>
}
</select>
</form>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ActionsComponent {
private userService = inject(UserService);
protected action = signal(undefined);
protected actions = ['Create', 'Read', 'Update', 'Delete'];
logMessage(action: string | undefined) {
this.userService.log(action ?? 'No action selected');
}
}