Improve component typesript example

master
Kevin C. Coram 2019-12-31 14:49:50 -08:00
parent 1903b6f5c7
commit 3ddb416073
Signed by: kevin
GPG Key ID: 0342351B3D61AD35
1 changed files with 6 additions and 0 deletions

View File

@ -3,6 +3,11 @@
The easiest way to create a simple Reactive Form is to use a single Angular component to build and display the form. In this example application, an asynchronous call to an API is simulated. The `Contact` object thus obtained is used to create and initialize a `FormGroup` using the Angular `FormBuilder`.
```typescript
export class AppComponent implements OnInit, OnDestroy {
form: FormGroup;
private subscription: Subscription;
public ngOnInit() {
this.subscription = this.service
.loadContact()
@ -47,6 +52,7 @@ The easiest way to create a simple Reactive Form is to use a single Angular comp
get addresses(): FormArray {
return this.form.get('addresses') as FormArray;
}
}
```
The component's template remders input controls for the Contact's name, and iterates over the array of addresses to render controls to edit each one.