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`.
|
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
|
```typescript
|
||||||
|
export class AppComponent implements OnInit, OnDestroy {
|
||||||
|
form: FormGroup;
|
||||||
|
|
||||||
|
private subscription: Subscription;
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
this.subscription = this.service
|
this.subscription = this.service
|
||||||
.loadContact()
|
.loadContact()
|
||||||
|
@ -47,6 +52,7 @@ The easiest way to create a simple Reactive Form is to use a single Angular comp
|
||||||
get addresses(): FormArray {
|
get addresses(): FormArray {
|
||||||
return this.form.get('addresses') as 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.
|
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