krzyhub krzyhub - 3 months ago 12
AngularJS Question

Angular ES6 - $inject is not a function

I just started to learn Angular ES6 way. I am analyzing this example from github: https://github.com/sitepoint-editors/Angular-ES6-BookShelf/blob/master/app/Controllers/HomeController.js

And I tried by myselfe:

class ModalCtrl {
constructor($scope, $rootScope, app) {
$rootScope.$on('openModal', (event, data) => {
$scope.data = data;
$scope.modalClass = 'open';
});
}
}

ModalCtrl.$inject(['$scope', '$rootScope', 'app']);

export default ModalCtrl;


But I get
app.min.js:60 Uncaught TypeError: ModalCtrl.$inject is not a function

What I am doing wrong and how to make this proper way?

Answer

As far I know you should use the $inject this way:

ModalCtrl.$inject = ['$scope', '$rootScope', 'app'];