我有一个Employee组件-
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});
}
}
我在尝试将新员工 push 列表的那行出现错误。
但这不是一种方法吗?我在这里想念什么吗?
最佳答案
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));
}
}