O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Private/Public modifiers

In TypeScript, all members in a class are public by default. We have to add the private keyword explicitly to control the visibility of the members:

class SimpleCalculator {     private x: number;     private y: number;     z: number;     constructor(x: number, y: number) {        this.x = x;        this.y = y;     }     addition() {         z = x + y;     }     subtraction() {         z = x - y;     } } class ComplexCalculator {     z: number;     constructor(private x: number, private y: number) { }     multiplication() {         z = this.x * this.y;     }     division() {         z = this.x / this.y;     } } 

Note that in the SimpleCalculator class, we defined x and y as private properties, which will not be visible outside the class. In ComplexCalculator, we defined x and y using parameter properties. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required