【发布时间】:2018-08-09 23:07:31
【问题描述】:
在 Ionic 2 中声明模型时,我看到有两个这样做。通过接口或类
接口代码:
export interface BlogPost {
postId: number,
title: string
}
类代码:
export class BlogPost{
public object: {};
constructor(
public postId: number,
public title: string
) {
this.object = {
postId: this.postId,
title: this.title,
};
}
}
我不确定它们之间有什么区别,有什么方法可以让我们在 Ionic 2 中提前声明一个预定义的值。就像
export interface BlogPost {
postId: number,
title: string,
comments: string = 'Test'
}
谢谢,
【问题讨论】:
标签: typescript ionic-framework ionic2 ionic3