angular 个模型中的对象 Declaration/Relationship
Object Declaration/Relationship in angular models
是否可以做这样的事情
我想在我的模型中声明一个对象,我尝试的第一个是
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;
}
我的终端出现 return 个错误:
第一个 returns 期望,但是当我做到时,它说我应该使用 eg:number 作为类型而不是值。
然后第二个return出错
找不到名称 '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")];
}
是否可以做这样的事情 我想在我的模型中声明一个对象,我尝试的第一个是
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;
}
我的终端出现 return 个错误: 第一个 returns 期望,但是当我做到时,它说我应该使用 eg:number 作为类型而不是值。
然后第二个return出错
找不到名称 '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")];
}