December 2017
Beginner
372 pages
10h 32m
English
The purpose of the news model class is to encapsulate the set of articles for each news channel. Let's refactor this class to now use the IArticle interface and a constructor. The following is the code of the original news.ts file:
import {Article} from './article';export class News { status:string; source:string; sortBy:string; articles: Article[];}
We have four properties, out of which, one is for an array of articles. The first change will be to use the constructor function that we learned in this chapter to accept the values of the three properties:
constructor(public status:string, public source:string, public sortBy:string ){}
As we know, in TypeScript, we can define a property and initialize its values in ...
Read now
Unlock full access