diff --git a/src/app/app.component.html b/src/app/app.component.html index 6438df3..599835b 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,9 +1,9 @@ -
-
帳號:
-
密碼:
-
- - +
+
+ + + +
-
{{ form.value | json }}
+
{{form.value| json}}
diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9834cfe..777fab3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; +import { FormArray, FormControl, FormGroup } from '@angular/forms'; @Component({ @@ -9,8 +9,20 @@ import { FormControl, FormGroup } from '@angular/forms'; }) export class AppComponent { readonly form = new FormGroup({ - id:new FormControl(), - password: new FormControl(), + Tasks: new FormArray([]), }); + get tasks(): FormArray{ + return this.form.get('Tasks') as FormArray; + } + + ngOnInit(): void{ + this.tasks.push(//注意此push用法 + new FormGroup({ + Subject: new FormControl(), + Content: new FormControl(), + }) + ); + } + }