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
module() method creates an application module, where the first parameter is a module name which is same as specified by ng-app directive.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With