Angular ngModel不是绑定数据

时间:2017-08-21 16:34:19

标签: html html5 angular angular2-forms

当我点击编辑按钮电子邮件文本框是绑定但是为什么Salary文本框不是绑定

<form class="form-horizontal" novalidate [formGroup]="EmployeeForm">
    <fieldset>   
<div [ngClass]="{'has-error':(EmployeeForm.get('Email').touched||
            EmployeeForm.get('Email').dirty) && !EmployeeForm.get('Email').valid}">
            <label>Email</label>
            <input type="email" formControlName="Email" [(ngModel)]="EmployeeForm.Email" />
        </div>

        <div [ngClass]="{'has-error':(EmployeeForm.get('sal').touched||
            EmployeeForm.get('sal').dirty) && !EmployeeForm.get('sal').valid}">
            <b>Salary...</b>
            <input type="number" formControlName="sal" [(ngModel)]="EmployeeForm.sal" />
        </div>

EditButtonCode

这是我的FormGroup代码这里我验证了我的专栏

 ngOnInit(): void {
        // this.CascadingComponent.GetCountry();
        this.EmployeeForm = this.fb.group({
            Emp_Id: ['', [Validators.required]],
            EmpName: ['', [Validators.required]],
            Psw: ['', Validators.compose([Validators.required, Validators.maxLength(6)])],
            Gen: ['', [Validators.required]],
            //   Cpsw: ['', [Validators.required, Validators.maxLength(6)]]
            //}, { validator: this.checkIfMatchingPasswords('Psw', 'Cpsw')
            Email: ['', [Validators.required]],
            sal: ['', [Validators.required]],
            Cnt_Name: ['', [Validators.required]],
            Dept_Name:['', [Validators.required]]
        })

    }

    EditEmp(Selected: Employee) {
            this.EmployeeForm.setValue(Selected);
        }

0 个答案:

没有答案