有没有办法在声明angular2数据模型时引用打字稿中的数据类型 [英] Is there a way to ref a data type in typescript while declaring an angular2 data model
本文介绍了有没有办法在声明angular2数据模型时引用打字稿中的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Mongoose中,它可以引用另一个数据定义.我想知道在为angular2定义数据模块时是否可以做些什么?
In Mongoose, it has a way to refer to another data definition. I wonder if there is a way we can do while we are defining a data module for angular2?
猫鼬
var personSchema = Schema({
_id : Number,
name : String,
age : Number,
stories : [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});
我的问题:
export class Person {
_id : number;
name : String;
age : Number;
stories : [
//sometype
]
}
推荐答案
Ha我找到了答案. 基本上,我需要做的是声明另一个如下所示的类:
Ha I found the answer for this. Basically, what I need to do is declare another class like the following:
export interface Story {
//some fields
}
import {Story} from "./story";
export class Person {
_id : number;
name : String;
age : Number;
stories : [
Story
]
}
这篇关于有没有办法在声明angular2数据模型时引用打字稿中的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文