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

前端 未结 1 456
小蘑菇
小蘑菇 2021-01-02 12:44

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

1条回答
  •  时光说笑
    2021-01-02 13:13

    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.

    0 讨论(0)
提交回复
热议问题