Seeking to streamline the process of importing services into Angular 4 components, I devised a solution like this:
import * as UtilityService from '../../services/utility.service';
As opposed to individually importing each service like so:
import { AppStateService, InternalStateType } from '../services/appstate.service';
import { Logging } from '../services/utility.service';
import { AuthenticationService } from '../services/authentication.service';
import { DataService } from '../services/data.service';
import { Utils } from '../services/utility.service';
import { RouteProtectionService } from '../services/route-protection.service';
import { UrlManagementService } from '../services/url-managing.service';
This enables me to access all classes from any component by referring to UtilityService.Classname
, such as UtilityService.AppState
, UtilityService.Authentication
, etc.
constructor(
public appState: UtilityService.AppState,
public utilities: UtilityService.Utils,
public dataService: UtilityService.Data,
private appInsightsService: UtilityService.AppInsights,
private titleService: UtilityService.Titles) {
}
Within utility.service.ts, I organize it as follows:
export { AppState, InternalStateType } from './appstate.service';
export { Authentication } from './authentication.service';
export { Data } from './data.service';
export { RouteProtection } from './route-protection.service';
export { UrlManagement } from './url-managing.service';
export { AppInsightsService } from '@markpieszak/ng-application-insights';
export { Title } from '@angular/platform-browser';
While it compiles without error in TypeScript, when running the application, Angular raises the following complaint:
Error: Can't resolve all parameters for Authentication: ([object Object], [object Object], ?, ?, ?).
I have already defined providers for each class in the AppModule, and they work when imported individually. So why am I encountering issues when attempting to import a group of classes using a barrel?