Working on an Angular 1.x app, using ES6, an Angular Linter, and Babel for transpiling. I am receiving this error: "TypeError: Cannot call a class as a function" in the console, though the html loads just fine.
TypeError: Cannot call a class as a function
at _classCallCheck (bundle.js:97664)
at Object.loginNotifyService (bundle.js:97670)
at Object.invoke (bundle.js:23052)
at Object.enforcedReturnValue [as $get] (bundle.js:22885)
at Object.invoke (bundle.js:23052)
at bundle.js:22844
at getService (bundle.js:22993)
at injectionArgs (bundle.js:23018)
at Object.invoke (bundle.js:23044)
at $controllerInit (bundle.js:29012) "<div ui-view="" class="ng-scope">"
Best I can tell, syntax is correct. My best guess is Babel transpiling to ES5, specifically this:
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
Here is the source JS:
'use strict';
class loginNotifyService {
constructor (notify) {
this.loginNotifyService = notify;
}
info (message, config) {
config = config || {};
config.message = message;
config.classes = 'alert alert-info ' + (config.classes || '');
return this.loginNotifyService(config);
}
warn (message, config) {
config = config || {};
config.message = message;
config.classes = 'alert alert-warning ' + (config.classes || '');
return this.loginNotifyService(config);
}
error (message, config) {
config = config || {};
config.message = message;
config.classes = 'alert alert-danger ' + (config.classes || '');
return this.loginNotifyService(config);
}
success (message, config) {
config = config || {};
config.message = message;
config.classes = 'alert alert-success ' + (config.classes || '');
return this.loginNotifyService(config);
}
notify (config) {
return this.loginNotifyService(config);
}
closeAll () {
return this.loginNotifyService.closeAll();
}
}
// loginNotifyService.$inject = ['notify'];
/* @ngInject */
export default loginNotifyService;
Here is the Controller that the loginNotifyService interacts with:
'use strict';
class loginController {
constructor ($state, loginNotifyService, loginService) {
this.$state = $state;
this.loginNotifyService = loginNotifyService;
this.loginService = loginService;
this.loginInProgress = false;
}
login () {
this.loginNotifyService.closeAll();
this.loginInProgress = true;
this.loginService.login(this.email, this.password).then(
() => {
this.loginInProgress = false;
this.$state.go('dashboard');
},
(error) => {
this.loginInProgress = false;
this.showErrors(error);
}
);
}
showErrors (error) {
this.errors = error;
this.loginNotifyService.error(error);
}
}
// loginController.$inject = ['$state', 'loginNotifyService', 'loginService'];
/* @ngInject */
export default loginController;
LMK if further clarification or info needed, and thank you for any advice.