olov / ng-annotate

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

Support for annotating template and templateUrl properties on angular 1.5 component #231

Closed martiansnoop closed 8 years ago

martiansnoop commented 8 years ago

ng-annotate version: 1.2.1

It appears that with the new component, the template and templateUrl properties can also be a function called by the injector (forgive the toy example):

angular.module("myModule", [])
   .component("myComponent", {
        template: function($log) {
            $log.debug("doing a thing");
            return "<div>My Template</div>"
        },
       ...
 });

It doesn't look like ng-annotate is currently annotating these, though, so I had to fall back to the array syntax:

        template: ["$log", function($log) {
            $log.debug("doing a thing");
            return "<div>My Template</div>"
        }],
gaelollivier commented 8 years ago

+1

However you can avoid the array syntax using an explicit annotation:

.component('my-app', {
    // @ngInject
    templateUrl: ($locale) => `views/${$locale.id}/app/app.html`,
    controller: Controller
})
michahell commented 8 years ago

Correct, the new angular 1.5 way of defining components breaks ngAnnotate / uglify. Unknown provider: aProvider <- a is the error that is given in my case.

brunomrpx commented 8 years ago

:+1:

konclave commented 8 years ago

+1

rothlis commented 8 years ago

+1

jeremypele commented 8 years ago

+1

olov commented 8 years ago

https://github.com/olov/ng-annotate/issues/245

Splaktar commented 8 years ago

This is also an issue with controllers, i.e. this doesn't work (Unknown provider: aProvider <- a):

angular.module('myApp').component('sox', {
  controller: SoxController,
...
});

function SoxController($rootScope) {
...

While this does:

angular.module('myApp').component('sox', {
  controller: SoxController,
...
});
SoxController.$inject = ['$rootScope'];
function SoxController($rootScope) {
...
canac commented 7 years ago

This feature would be useful in my application as well. Explicit annotation works fine, but it would be nice if this were automatic. @olov Does your closing this issue mean that this feature won't ever be added?

omsmith commented 7 years ago

@canac changes won't be made to ng-annotate going forward: https://github.com/olov/ng-annotate/issues/245