Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate Angular 2 RC 1 (or earlier) Forms to Angular 2 RC 2 / RC 4 New Forms

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.

like image 700
Naveed Ahmed Avatar asked Jun 17 '16 00:06

Naveed Ahmed


1 Answers

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.

like image 142
Naveed Ahmed Avatar answered Nov 19 '22 11:11

Naveed Ahmed