如何将formControl值绑定到表单输入

时间:2019-03-01 13:46:54

标签: angular angular-reactive-forms

我有角度分量:

import { Component, OnInit, Inject } from '@angular/core';

import {FormBuilder, FormGroup,Validators,FormArray,FormControl,} from '@angular/forms';

@Component({
    selector: 'app-collaborator-detail',
    template: `
    <h1> This is form</h1>
    <form [formGroup]="collaboratorForm">
    <div>
        <input type="text" placeholder="Email address" formControlName="emailAddress">
    </div>
</form>`,
})
export class CollaboratorDetailComponent implements OnInit {
    constructor(@Inject(FormBuilder) private fb: FormBuilder) {}

    collaboratorForm: FormGroup;

    ngOnInit() {
        this.initCollaboratorForm();
    }

    initCollaboratorForm() {
        this.collaboratorForm = this.fb.group({
            emailAddress: [
                { value: 'some.email@gmail.com', disable: true },
                [Validators.email, Validators.required],
            ]
        });
    }
}

我希望该值:“ some-email@gmail.com”将作为输入值可见。但是代替它的是,可见值是:“ [object Object]”。

我在这里做错了什么?

柱塞URL:https://next.plnkr.co/edit/wu1ow98ai00gqJ4s

1 个答案:

答案 0 :(得分:1)

AbstractControl API(所有表单控件的基类)中没有名为disable的属性,它应该是disabled

{ value: 'some.email@gmail.com', disabled: true }