liveBook · Manning

MVC model

As explained in Pro Angular 16

A model class is a class that defines the structure and data properties of an entity in an application's data model.

A model class describes the data an application works with. A data model can also include a data source that loads and saves data and a repository that lets the application manipulate it. Product classes can be added first, with other classes introduced as features require them. section 5.3.1 section 9.6.1

Product class

A TypeScript Product class can declare optional constructor properties for an identifier, name, category, description, and price. Optional properties are useful when an HTML form populates an object. section 5.3.1

Listing 5.11. The contents of the product.model.ts file in the src/app/model folder
export class Product {
 
    constructor(
        public id?: number,
        public name?: string,
        public category?: string,
        public description?: string,
        public price?: number) { }
}

View a complete Product class with its optional constructor properties. section 5.3.1

How Pro Angular 16 covers it

How deep it goes
Defines entity properties through optional constructor arguments, while leaving data loading and manipulation to separate model parts.
Examples
Uses a Product class with identifier, name, category, description, and price properties, including optional arguments for form-created objects.
What you can do after
Build it from scratch by declaring a TypeScript class with optional constructor properties that describe an entity's data.
How it connects
Connects descriptive classes to data sources and repositories as parts of a data model.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.