[英]Typescript Class as a Member Variable in Angular?
I'm learning Angular and TypeScript and I have a question or two. 我正在学习Angular和TypeScript,但有一个或两个问题。
With TypeScript can you have one class/object be the variable type for an other object as shown below? 使用TypeScript,您可以让一个类/对象成为另一对象的变量类型,如下所示吗? If so how do you reference the all of the members using Angular.
如果是这样,您如何使用Angular引用所有成员。
/* begin cmsfiles.ts */
export class CMSFiles {
fileID: number;
fileDateTime: Date;
fileName: string;
description: string;
}
/* end cmsfiles.ts */
/* begin news.ts */
import { CMSFiles } from './cmsfiles';
export class News {
newsID: number;
postDateTime: Date;
title: string;
body: string;
file1: CMSFiles;
file2: CMSFiles;
}
/* end news.ts */
In the Angular template I will need to use something like this: 在Angular模板中,我将需要使用以下内容:
<input [(ngModel)]="news.file1.Title" placeholder="title" />
How can I achieve this? 我该如何实现?
Classes define types. 类定义类型。 Those types can be used wherever any of the default types can be used.
只要可以使用任何默认类型,就可以使用这些类型。
In short yes. 简而言之,是的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.