Improve component typesript example
parent
1903b6f5c7
commit
3ddb416073
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue