angularjs - ECMA6 class-based controller with babel and ng-annotate/ngInject results in ReferenceError -


i've angular 1.4 controller method depends on resource service. i've annotated constructor of class ng-annotate, still, angular curses service can't found in method:

var myresourcefactory = require("myresource.service");  class mycontroller {     // @nginject     constructor($location, $stateparams, $state, myresource) {         ... // initialization code     }      mymethod(data) {         var resource = new myresource();         resource.data = data;         resource.save();     } }  module.exports = angular.module("mymodule", [])     .factory('myresource', myresourcefactory)     .controller('mycontroller', mycontroller)     .config(routes); 

but, on first line of mymethod (var resource = new myresource()) execution fails:

referenceerror: myresource undefined     @ mycontroller.mymethod (mymodule.module.js:214)     ... 

technologies used:

  • angular 1.4
  • webpack
  • babel
  • ng-annotate

how apply nginject ecma6-class method?

myresource variable local constructor method , it's not available outside. usual approach in such cases, make public property:

class mycontroller {     // @nginject     constructor($location, $stateparams, $state, myresource) {         this.myresource = myresource;         // ... initialization code     }      mymethod(data) {         var resource = new this.myresource();         resource.data = data;         resource.save();     } }