角色2 RC4中的形式

我正在试验角度2 RC4中的形式.
这一切都很好,但是当我启动应用程序浏览器控制台给我这个消息:
*It looks like you're using the old forms module. This will be opt-in in the next RC,and will eventually be removed in favor of the new forms module.

我的组件的相关部分如下所示:

import {
    FORM_DIRECTIVES,REACTIVE_FORM_DIRECTIVES,FormBuilder,FormGroup
} from '@angular/forms';
import {Observable} from "rxjs/Rx";

@Component
({
    selector: "hh-topbar",moduleId: module.id,templateUrl: "topBar.component.html",directives: [HHPagerComponent,FORM_DIRECTIVES,REACTIVE_FORM_DIRECTIVES]
})

export class HHTopBarComponent implements OnChanges,OnInit
{
    ...
    private filterForm: FormGroup;
    private title$: Observable<string>;

    constructor(private formBuilder: FormBuilder)
    {
    }

    public ngOnInit(): any
    {
        this.filterForm = this.formBuilder.group
        ({
            "title": [this.info.filters.searchFileName]
        });

        this.title$= this.filterForm.controls["title"].valueChanges;
        this.title$.subscribe(val =>
        {
            this.info.filters.searchFileName = val;
            this.filterChanged.emit(this.info.filters);
        });
    }
}

我的模板的相关部分如下所示:

<form [formGroup]="filterForm">
    <div>
        <label for="title">Title</label>
        <input [formControl]="filterForm.controls['title']" id="title" />
    </div>
</form>

有谁在这里知道警告所说的新形式模块是什么,哪些指令会改变什么?

您需要在引导应用程序时明确禁用不支持的表单支持
import {disableDeprecatedForms,provideForms} from '@angular/forms';

bootstrap(AppComponent,[
  disableDeprecatedForms()
  provideForms()
]);

而FormBuilder不被弃用,您可以直接使用FormGroup类:

this.filterForm = new FormGroup({
  title: new FormControl('',Validators.required)
});

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...