Skip to content

// @ngInject does not work if first line in file #13

@filipesilva

Description

@filipesilva

Using this loader

  module: {
    loaders: [{
      test: /\.js$/,
      include: path.resolve(__dirname, 'app/'),
      loaders: ['ng-annotate', 'babel-loader']
    }, 
    (...)

If my file contains, for example

// @ngInject
function controller($stateParams, session, tiles, organizations) {
  let vm = this;
}

It gets compiled to

// @ngInject
'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});

function controller($stateParams, session, tiles, organizations) {
  var vm = this;
}
exports["default"] = controller;
module.exports = exports["default"];

Causing the annotation to not work. In contrast, with if the comment is not the first line

let number = 1;

// @ngInject
function controller($stateParams, session, tiles, organizations) {
  let vm = this;
}

export default controller;

It compiles well

    "use strict";

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    var number = 1;

    // @ngInject
    function controller($stateParams, session, tiles, organizations) {
      var vm = this;
    }
    controller.$inject = ["$stateParams", "session", "tiles", "organizations"];

    exports["default"] = controller;
    module.exports = exports["default"];

I tried using the "ngInject" syntax and it works. Any suggestion to get the // @ngInject syntax to work as well in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions