This article follows the first six on the subject ANGULAR and deals with the language TypeScript:
- https://128mots.com/index.php/2020/02/29/angular-en-moins-de-128-mots-typescript-partie-3/
- https://128mots.com/index.php/2020/02/28/angular-en-moins-de-128-mots-partie-2/
- https://128mots.com/index.php/2020/02/27/angular-en-plus-de-128-mots-partie-1/
- https://128mots.com/index.php/2020/03/02/typescript-part4/
- https://128mots.com/index.php/2020/03/24/angular-en-moins-de-128-mots-typescript-partie-5/
- https://128mots.com/index.php/2020/03/25/angular-component/
Manufacturer:
The builder is the method called to create the instance of an object
Class Point x: number; y: number; constructor (x: number, y: number) this.x x; this.y - y; } add (point: Point) return new Point (this.x - point.x, this.y - point.y); } } var p1 - new Point (30, 5); var p2 - new Point (14, 21); var p3 - p1.add (p2);
Optional setting:
If a setting is declared optional then all the parameters declared to its right are optional. Example of the name setting in the manufacturer.
Class Point x: number; y: number; name: string; constructor (x: number, y: number, name?:string) this.x x; this.y - y; this.name - name; } }
Visibility:
By default the visibility of the setting is public, you can use "access modifiers" to change it.
Class Point private x: number;
Access modifiers can be positioned on methods, variables and properties.
Class Point ... private add (point: Point) return new Point (this.x - point.x, this.y - point.y); } }
Class Point ... constructor (private x: number, private y: number) ...
Adding an access modifier (public/private/protected/reading only) to a builder setting will automatically assign that setting to a field of the same name.
Getter and setter:
TypeScript supports getters/setters as a way to intercept access to a member of an object.
This allows for a finer control over how a member is accessed on each object.
Const lengthMaxDuNom - 10; Wage class private _nomComplet: string; get nameComplet(): thong return this._nomComplet; } name setComplet (newName: string) if (newName - newNom.length - lengthMaxDuNom) throw new Error ("Error Maximum length of the name reached, maximum length allowed - " lengthMaxDuNom); } this._nomComplet - newName; } } let salarie - new Salarie(); salarie.nameComplet - "Toto Hello"; if (employee.nomComplete) console.log (employee.nameComplete); }
References to read: