本文介绍了如何将Angular 2 RC 1(或更早版本)表单迁移到Angular 2 RC 2/RC 4新表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将现有的Angular 2 RC 1应用程序迁移到Angular 2 RC4.作为其中一部分,我还需要将现有的表单移至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新表单时遇到困难的人.这是他们需要遵循的步骤:

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新表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:34