How to import a TypeScript class with names in Angular 2

Given the TypeScript class, which is referred to as the TS module, in the CoolApps.Utilities.ts file:

module CoolApps { export class Utilities { myMethod(){ alert("something awesome"); } } } 

The class works in a regular TypeScript application, but I'm trying to understand our correct way of referencing this class in Angular 2. How to use it in an Angular 2 application (Ionic 2 in case)? So far, the following does not resolve, so I probably misunderstand the syntax:

 import {Page} from 'ionic-framework/ionic'; import {Utilities} from '../../core/CoolApps.Utilities'; 

Using such a link will allow the editor to see the code as valid, but Angular cannot solve it (maybe the import only works for Angular specific modules?):

 ///<reference path="../../core/mapping/OCM.Mapping.ts"/> 
+6
source share
1 answer

Import:

 import {CoolApps} from '../../core/CoolApps.Utilities'; 

Class Usage Example

 let util : CoolApps.Utilities = new CoolApps.Utilities(); 

You can also remove the module declaration from CoolApps.Utilities.ts and convert the import as follows:

 import * as CoolApps from '../../core/CoolApps.Utilities'; 
+5
source

All Articles