I decided to put LoginComponent, AuthService, LoggedInGuard inside the AuthModule module:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { AuthComponent } from './auth.component';
import { LoginComponent } from './components/login/login.component';
import { AuthService } from './services/auth/auth.service';
import { StorageService } from './services/storage/storage.service';
import { RequestService } from './services/request/request.service';
import { LoggedInGuard } from './guards/logged-in.guard';
@NgModule({
imports: [
CommonModule
],
providers: [AuthService, LoggedInGuard],
declarations: [AuthComponent, LoginComponent],
exports: [AuthService, LoggedInGuard]
})
export class AuthModule { }
And I want to use only AuthService methods in the rest of the application. And LoggedInGuard to protect non-public routes.
So, I tried to import them into the AppModule:
import { AuthModule } from './core/auth/auth.module';
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
AuthModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
But in app.routes.ts, LoggedInGuard is not available with this line of code:
import { LoggedInGuard } from './core/auth/auth.module';
It does not compile, and it says:
... auth / auth.module does not have an exported element 'LoggedInGuard'
If I point it to the right place:
import { LoggedInGuard } from './core/auth/guards/logged-in.guard';
It compiles, but shows the following runtime error:
Unexpected value 'AuthService' exported by module 'AuthModule'
What do you offer me?
Thanks in advance.