I'm facing an issue with injecting services into my controller. Below is the code and the outcome of this process.
user.service.js:
class UsersService{
constructor(){}
usersServiceFn () {
return {
name: 'TEST'
};
};
}
export default UsersService;
users.jsp:
import UsersService from './users.service';
export default app => {
app.factory('users', UsersService);
if (ENVIRONMENT === 'test') {
require('./users.test.js');
}
}
service.js:
import usersService from './users/users';
export default app => {
INCLUDE_ALL_MODULES([usersService], app);
}
index.js:
import angular from 'angular';
import angularUIRouter from 'angular-ui-router';
import appComponents from './components/components.js';
import commonComponents from './common/components.js';
import appServices from './services/services.js';
import appConfiguration from './app.config';
// Single Style Entry Point
import './index.scss';
if (ENVIRONMENT === 'test') {
console.log('ENV:', ENVIRONMENT);
require('angular-mocks/angular-mocks');
}
const app = angular.module('app', ['ui.router']);
appComponents(app);
commonComponents(app);
appServices(app);
home.controller.js:
class HomeController {
constructor($scope, $http, usersService) {
this.$scope = $scope;
this.$http = $http;
this.usersService = usersService;
this.$scope.persons = null;
this.name = 'home';
this.$scope.surname ='ZZZZZZ';
this.$scope.randomNumb = Math.random();
this.initRecords();
this.range();
this.watchText();
}
/..../
}
HomeController.$inject = ['$scope', '$http', 'usersService'];
export default HomeController;
And here's the outcome:
I've been trying to troubleshoot but I'm unsure of where the problem lies.
**structure: **