krzyhub krzyhub - 1 year ago 115
AngularJS Question

Angular ES6 - $inject is not a function

I just started to learn Angular ES6 way. I am analyzing this example from github:

And I tried by myselfe:

class ModalCtrl {
constructor($scope, $rootScope, app) {
$rootScope.$on('openModal', (event, 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 Source

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

ModalCtrl.$inject = ['$scope', '$rootScope', 'app'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download