I need to migrate my existing Angular 2 RC 1 app to Angular 2 RC 4. As a part of which I also need to move my existing forms to Angular 2 RC 4 New Forms.
Can anyone please guide, how to update existing forms to new form.
For those who are having trouble in migrating forms from Angular 2 RC 1 (or earlier) to Angular 2 RC 2 / RC 4 New Forms. Here are the steps they need to follow:
Include new forms in your project by adding below package to their packages.json:
"@angular/forms": "0.2.0",
Next, they have to disable the deprecated forms in main file and include new forms something like below:
import {disableDeprecatedForms, provideForms} from '@angular/forms';
bootstrap(AppComponent, [
disableDeprecatedForms(),
provideForms()
])
Then in their component add import for new form directives:
import { REACTIVE_FORM_DIRECTIVES, FormControl, FormGroup, FormBuilder, Validators } from '@angular/forms';
Include REACTIVE_FORM_DIRECTIVES for the component:
directives: [REACTIVE_FORM_DIRECTIVES],
In your component rename the following:
ControlGroup > FormGroup
Control > FormControl
In your templates rename the following:
ngFormModel > formGroup
ngControl > formControlName
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With