I'm learning Angular and TypeScript and I have a question or two.

With TypeScript can you have one class/object be the variable type for an other object as shown below? If so how do you reference the all of the members using 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:

<input [(ngModel)]="news.file1.Title" placeholder="title" />

How can I achieve this?

share|improve this question
    
The field Title doesn't exist on CMSFiles. Did you mean fileName? – cdbajorin Jan 11 '17 at 19:37
    
Yes, you are correct I do mean fileName and not title. – Pete Letkeman Jan 11 '17 at 20:17
up vote 0 down vote accepted

Classes define types. Those types can be used wherever any of the default types can be used.

In short yes.

share|improve this answer
    
do you know if <input [(ngModel)]="news.file1.fileName" placeholder="fileName" /> is correct syntax? – Pete Letkeman Jan 11 '17 at 20:18
    
if the properties of the CMSFiles class are public yes. :) It's just normal js notation – toskv Jan 11 '17 at 20:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.