xilex
3/9/2020 - 4:35 AM

angular: models

// two methods to code a simple model

// method one (conventional)
export class Ingredient {
    public name: string; // name of ingredient
    public amount: number;

    constructor(name: string, amount: number) {
        this.name = name;
        this.amount = amount;
    }
}

// method two (shorthand) automatically create variables (declared as public) and then assign arguments to those variables
export class Ingredient {
    constructor(public name: string, public amount: number) {}
}