我有一个员工组件 -
export class EmployeeComponent{
name:string;
isEditOn:boolean;
constructor(){}
toggleEdit():void{
this.isEditOn = !this.isEditOn;
}
}
和像这样的员工列表组件 -
export class EmployeeListComponent{
employees: Employee[] = [];
AddNewEmployee(){
this.employees.push({name:"New Employee", isEditOn:false});
}
}
我在尝试将新员工推入列表中的行上出现错误。
属性 'toggleEdit' 在类型 '{ name: string; isEditOn: false; }' 中缺失。
但这不是一种方法吗?我在这里错过了什么吗?
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));
}
}