ts-ng-annotate adds and fixes dependency annotations of AngularJS on TypeScript files.
The following steps add and fix annotations in place:
git clone https://github.com/kabuku/ts-ng-annotate.git
cd ts-ng-annotate
npm install
./node_modules/.bin/ts-node ts-ng-annotate-main.ts /path/to/ts-file...
ts-ng-annotate supports the following code:
- Inline function like argument of
angular.Module
method call which follows AngularJS Style Guide (Definitions (aka Setters)) - Function like expression which has
'ngInject'
prologue - Constructor which has
'ngInject'
prologue
where function like means function expression or arrow function.
// Before
angular.module('myapp').factory('MyService', ($http) => {});
// After
angular.module('myapp').factory('MyService', ['$http', ($http) => {}]);
// Before
class MyService {
constructor($http) {
'ngInject';
}
}
// After
class MyService {
static $inject = ['$http'];
constructor($http) {
'ngInject';
}
}
MIT