我试图了解如何创建包含数组的模型。 我试图做这样的事情,但我收到了一个错误:
ERRROR
Argument of type 'elset' is not assignable to parameter of type 'elset[]'.
MODEL
export class elset{
constructor(
public name: string,
public title: string
){}
}
export class pageModel{
constructor(
public type: string,
public set: elset[]
){}
}
服务
@Injectable()
export class customService {
constructor ( ){}
types = [
new pageModel('home',
new elset('something','somethingelse')
)
];
}
答案 0 :(得分:2)
您在此处将第二个参数定义为 elset
个实例的数组:
export class pageModel{
constructor(
public type: string,
public set: elset[] <--------------------
){}
}
所以你需要传递一个数组:
new pageModel('home', [new elset('something','somethingelse')])