Currently working on an Angular 1.x application, utilizing ES6, an Angular Linter, and Babel for transpiling. Encountering an error message: "TypeError: Cannot call a class as a function" in the console, even though the HTML loads correctly.
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">"
From my analysis, it appears that the syntax is correct. My assumption is that Babel is converting to ES5, specifically this snippet:
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
Below is the source JavaScript code:
'use strict';
class loginNotifyService {
constructor(notify) {
this.loginNotifyService = notify;
}
info(message, config) {
// Method details...
}
warn(message, config) {
// Method details...
}
error(message, config) {
// Method details...
}
success(message, config) {
// Method details...
}
notify(config) {
// Method details...
}
closeAll() {
// Method details...
}
}
// loginNotifyService.$inject = ['notify'];
/* @ngInject */
export default loginNotifyService;
And here is the Controller associated with the loginNotifyService:
'use strict';
class loginController {
constructor($state, loginNotifyService, loginService) {
// Constructor details...
}
login() {
// Method details...
}
showErrors(error) {
// Method details...
}
}
// loginController.$inject = ['$state', 'loginNotifyService', 'loginService'];
/* @ngInject */
export default loginController;
If you require further clarification or additional information, please let me know. Thank you for any guidance offered.