0

在我的部门.component.html 中,我有这个:

专注于#form和召唤addDepartment(form.formValues)

<app-dialog-form *ngIf="showDialogBox" [(showDialogBox)]="showDialogBox" #form [values]="department">
    Register Department
    <div class="action" action>
        <button class="ui button basic" (click)="onToggleDialogBox()">Cancel</button>
        <button class="ui button primary medium" (click)="addDepartment(form.formValues)">Save</button>
    </div>
</app-dialog-form>

在我的 formValues 中获取值是这样的:

get formValues(): any {
  let data;
  data = this.dialogForm.value;
  return data;

}

这是我的 addDepartment() 代码

addDepartment(department: Department) {
    console.log(department.name);
    if (typeof department === 'object') {
        this.departmentService
        .registerDepartment(department)
        .subscribe(
            res => { alert(res); 
                    //this.goBackToDepartmentListPage(); 
                   },
            error => alert(error)
        )
    }
}

但是每次,我提交表单值并尝试在控制台中打印输入,我都会收到此错误

Cannot read property 'value' of undefined at 
DialogFormComponent.get [as formValues]
4

0 回答 0