加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

角色2 RC4中的形式

发布时间:2020-12-17 07:37:15 所属栏目:安全 来源:网络整理
导读:我正在试验角度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.
我正在试验角度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)
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读