有可能这样做吗我想在我的模型中声明一个对象,我尝试的第一个是
export class Employee{
emp_id: number;
emp_fname: string;
emp_lname: string;
emp_birth: string;
emp_status: string;
emp_photo: string;
emp_department: string;
department: Array<object> =
[{
dept_id: number;
dept_name: string;
}];
第二个像这个
import { Department } from "./department.model";
export class Employee{
constructor(department: Department){};
emp_id: number;
emp_fname: string;
emp_lname: string;
emp_birth: string;
emp_status: string;
emp_photo: string;
emp_department: string;
department: department;
}
我的终端中的两个返回错误:第一个返回expects,但当我这样做时,它说我应该使用eg:number作为类型,而不是值。
然后第二个返回错误
找不到名称"department"。
我的部门型号
export class Department {
dept_id: number;
dept_name: string;
}
export class Department {
dept_id: number;
dept_name: string;
constructor(dept_id, dept_name){
this.dept_id = dept_id;
this.dept_name = dept_name;
}
}
export class Employee{
emp_id: number;
emp_fname: string;
emp_lname: string;
emp_birth: string;
emp_status: string;
emp_photo: string;
emp_department: string;
department: Department[] = [new Department(1, "dept_name1"), new Department(2, "dept_name2")];
}