如何将模型数据传递到另一个模型
例如,我想将模型2 modelUser
注入模型1 user
..
model1.ts
export class model1{
constructor(private user: modelUser;){}
}
model2.ts
export class model2{
constructor(public modelUser: string){}
}
答案 0 :(得分:0)
Model1.ts
import { Model2} from './model2'
export class Model1{
user: Model2
}
Model2.ts
export class Model2{
id: Number
name: String
}
你可以用类似的东西从模型1中调用模型2
export class Model1{
...
someFunction(){
const userDetail = {
id: user.id
name: user.name
}
}
}
答案 1 :(得分:0)
包含构造函数的派生类必须调用super(),它将在基类上执行构造函数。
export class model2{
constructor(public modelUser: string){
console.log(modelUser);
}
}
export class model1 extends model2{
constructor(public modelUser: string){
super(modelUser);
console.log(this.modelUser)
}
}
let y=new model2('model2');
let x=new model1('model1');