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

Namespaces

We can create namespaces in TypeScript using the namespace keyword, as illustrated. All the classes defined under namespace will be scoped under that particular namespace and will not be attached to the global scope:

namespace Inventory {       Class Product {              constructor (public name: string, public quantity: number) {   }       }       // product is accessible       var p = new Product('mobile', 101); } // Product class is not accessible outside namespace var p = new Inventory.Product('mobile', 101); 

To make the Product class available outside the namespace, we need to add an export keyword when defining the Product class, as follows:

namespace Inventory {       export Class Product {  constructor (public name: string, public quantity: number) { } ...

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