角色2 RC4中的形式

前端之家收集整理的这篇文章主要介绍了角色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)
});
原文链接:https://www.f2er.com/angularjs/142576.html

猜你在找的Angularjs相关文章