如何将 Angular 2 RC 1(或更早版本)表单迁移到 Angular 2 RC 2/RC 4 新表单 [英] How to migrate Angular 2 RC 1 (or earlier) Forms to Angular 2 RC 2 / RC 4 New Forms
问题描述
我需要将我现有的 Angular 2 RC 1 应用程序迁移到 Angular 2 RC 4.作为其中的一部分,我还需要将我现有的表单移动到 Angular 2 RC 4 新表单.
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.
推荐答案
适用于那些在将表单从 Angular 2 RC 1(或更早版本)迁移到 Angular 2 RC 2/RC 4 New Forms 时遇到问题的人.以下是他们需要遵循的步骤:
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:
通过将以下包添加到它们的 packages.json 中,在您的项目中包含新表单:
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';
为组件包含 REACTIVE_FORM_DIRECTIVES:
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
我希望这会有所帮助.
这篇关于如何将 Angular 2 RC 1(或更早版本)表单迁移到 Angular 2 RC 2/RC 4 新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!