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

爷,独闯天下 提交于 2019-11-30 14:04:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!