回答編集履歴

1

実装例を追加しました。

2019/08/14 15:33

投稿

s14pes
s14pes

スコア55

test CHANGED
@@ -9,3 +9,75 @@
9
9
 
10
10
 
11
11
  https://angular.jp/guide/forms-overview
12
+
13
+
14
+
15
+ 追記:
16
+
17
+ 雑な解答をしてしまい申し訳なかったので実装してみました。
18
+
19
+
20
+
21
+ https://stackblitz.com/edit/angular-fz9ymg?file=app%2Fform-field-overview-example.ts
22
+
23
+
24
+
25
+
26
+
27
+ ```typescript
28
+
29
+ export class FormFieldOverviewExample {
30
+
31
+
32
+
33
+ myGroup = new FormGroup({
34
+
35
+ age: new FormControl()
36
+
37
+ });
38
+
39
+ // 変数宣言:プルダウンメニュー表示用
40
+
41
+ ages: Number[] = [
42
+
43
+ 21,
44
+
45
+ 22,
46
+
47
+ 23,
48
+
49
+ ];
50
+
51
+ // 関数:コンソール表示用
52
+
53
+ show(i) {
54
+
55
+ console.log(i);
56
+
57
+ }
58
+
59
+ }
60
+
61
+ ```
62
+
63
+
64
+
65
+ ```html
66
+
67
+ <form [formGroup]="myGroup" (ngSubmit)="show(myGroup.value.age)">
68
+
69
+ <mat-form-field>
70
+
71
+ <mat-select [formControlName]="'age'">
72
+
73
+ <mat-option *ngFor="let item of ages" value="{{item}}">{{item}}</mat-option>
74
+
75
+ </mat-select>
76
+
77
+ </mat-form-field>
78
+
79
+ <input type="submit" value="送信">
80
+
81
+ </form>
82
+
83
+ ```