Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement modules using Typescript 1.5 and AngularJS 1.4?

I have an Angular 1.4 application that was written using an earlier version of Typescript. Now I am looking to update this to use the new module capabilities that Typescript 1.5 gives me.

Does anyone have any examples of how I can implement modules with the new Typescript and current AngularJS. I have seen examples that don't use Typescript but have yet to find any example that uses Typescript that is for Angular 1.4

like image 870
Samantha J T Star Avatar asked Jul 26 '15 13:07

Samantha J T Star


People also ask

Which method is used to create module in AngularJS?

module() method creates an application module, where the first parameter is a module name which is same as specified by ng-app directive.

Where do I put angular modules?

While it is common in HTML applications to place scripts at the end of the <body> element, it is recommended that you load the AngularJS library either in the <head> or at the start of the <body> . This is because calls to angular. module can only be compiled after the library has been loaded.

What is an AngularJS module?

In AngularJS, a module defines an application. It is a container for the different parts of your application like controller, services, filters, directives etc. A module is used as a Main() method. Controller always belongs to a module.


1 Answers

Typescript 1.5 supports ES6 module syntax which are de-facto standard as of now because of the ES6 being officialy released as ES2015. Typescript 1.5 rebranded internal / external modules into namespace and modules and you should be doing it using modules. I have a github repository, where I am using this module import export syntax (without typescript but that doesn't matter because module import export syntax is the same). This example project was heavily inspired by reading this tutorial.

Generally speaking you also want to use some build tool (I recommend Webpack). Then you can take the code described in the links above and start adding types and interfaces and using TS classes instead of ES6 classes.

Edit: also you should use DefinitelyTyped repository for Angular JS declaration file

like image 92
tomastrajan Avatar answered Sep 20 '22 19:09

tomastrajan