olov / ng-annotate

Add, remove and rebuild AngularJS dependency injection annotations
MIT License
2.03k stars 152 forks source link

the comment way to use ng-annotate . #225

Closed lili21 closed 8 years ago

lili21 commented 8 years ago

the readme dose not cover well. Do all those comment way work ?

/** @ngInject */
/** @nginject */
/** inject */
/* @inject */

how many comments way can be used ?

and here is the weird situation I meet with。I am using ng-annotate-loader.

2016-01-26 4 54 07

It works well when using /** @ngInject */

2016-01-26 4 56 49

no $inject for NsServer, so it does not work when using /** @inject */. right ?

But how about this ? 2016-01-26 5 03 12

Looks like working fine.

the only difference between those /** @inject */ situations is the size of the code bases.

So what is the safest way to make it work ?

olov commented 8 years ago

From your example, /* @inject */ does not affect ng-annotate at all. ng-annotate succeeds in annotating one of the cases anyways using static analysis.

As for how to write the comment, do it however you want. /* @ngInject */, /*@ngInject*/, /** @ngInject */, // foo @ngInject bar etc all work fine. But the recommended way is to use "ngInject", as pointed out in the README.

lili21 commented 8 years ago

@olov You meat ng-annotate understands

angular.module('app', [])
    .ctrl('ctrl', ctrl)
    .factory('NsServer', NsServer)

and does not understand

_angular2.default.module('app').factory('NsServer', NsServer)
olov commented 8 years ago

That's correct. You can teach it to understand the latter form as well, see https://github.com/olov/ng-annotate/blob/master/IMPLICIT.md (search for regexp on page).

lili21 commented 8 years ago

@olov Now I got it. Thanks. Awesome job, by the way.