我有一个员工组件 -
export class EmployeeComponent{
name:string;
isEditOn:boolean;
constructor(){}
toggleEdit():void{
this.isEditOn = !this.isEditOn;
}
}
这样的EmployeeList组件 -
export class EmployeeListComponent{
employees: Employee[] = [];
AddNewEmployee(){
this.employees.push({name:"New Employee", isEditOn:false});
}
}
我正在尝试在列表中推送新员工的行上出现错误。
类型'{name:string;}中缺少属性'toggleEdit'; isEditOn:false; }”。
但这不是一种方法吗?我在这里错过了什么吗?
答案 0 :(得分:1)
export class Employee {
constructor(public name: string, public isEditOn: boolean){}
toggleEdit():void{
this.isEditOn = !this.isEditOn;
}
}

export class EmployeeListComponent{
employees: Employee[] = [];
AddNewEmployee(){
this.employees.push(new Employee("New Employee", false));
}
}