diff --git a/example-app/app/app.module.ts b/example-app/app/app.module.ts index d97bb7ff23..e55d6992fe 100644 --- a/example-app/app/app.module.ts +++ b/example-app/app/app.module.ts @@ -29,7 +29,7 @@ import { AppRoutingModule } from './app-routing.module'; BrowserModule, BrowserAnimationsModule, HttpClientModule, - AuthModule.forRoot(), + AuthModule, AppRoutingModule, /** @@ -82,7 +82,7 @@ import { AppRoutingModule } from './app-routing.module'; */ DBModule.provideDB(schema), - CoreModule.forRoot(), + CoreModule, ], bootstrap: [AppComponent], }) diff --git a/example-app/app/auth/auth.module.ts b/example-app/app/auth/auth.module.ts index 990790e363..27c8d79e5e 100644 --- a/example-app/app/auth/auth.module.ts +++ b/example-app/app/auth/auth.module.ts @@ -1,4 +1,4 @@ -import { NgModule, ModuleWithProviders } from '@angular/core'; +import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ReactiveFormsModule } from '@angular/forms'; import { StoreModule } from '@ngrx/store'; @@ -6,8 +6,6 @@ import { EffectsModule } from '@ngrx/effects'; import { LoginPageComponent } from './containers/login-page.component'; import { LoginFormComponent } from './components/login-form.component'; -import { AuthService } from './services/auth.service'; -import { AuthGuard } from './services/auth-guard.service'; import { AuthEffects } from './effects/auth.effects'; import { reducers } from './reducers'; import { MaterialModule } from '../material'; @@ -15,26 +13,15 @@ import { AuthRoutingModule } from './auth-routing.module'; export const COMPONENTS = [LoginPageComponent, LoginFormComponent]; -@NgModule({ - imports: [CommonModule, ReactiveFormsModule, MaterialModule], - declarations: COMPONENTS, - exports: COMPONENTS, -}) -export class AuthModule { - static forRoot(): ModuleWithProviders { - return { - ngModule: RootAuthModule, - providers: [AuthService, AuthGuard], - }; - } -} - @NgModule({ imports: [ - AuthModule, + CommonModule, + ReactiveFormsModule, + MaterialModule, AuthRoutingModule, StoreModule.forFeature('auth', reducers), EffectsModule.forFeature([AuthEffects]), ], + declarations: COMPONENTS, }) -export class RootAuthModule {} +export class AuthModule {} diff --git a/example-app/app/auth/services/auth-guard.service.spec.ts b/example-app/app/auth/services/auth-guard.service.spec.ts index 8ee66ae91a..cd9aa4b5a3 100644 --- a/example-app/app/auth/services/auth-guard.service.spec.ts +++ b/example-app/app/auth/services/auth-guard.service.spec.ts @@ -18,7 +18,6 @@ describe('Auth Guard', () => { auth: combineReducers(fromAuth.reducers), }), ], - providers: [AuthGuard], }); store = TestBed.get(Store); diff --git a/example-app/app/auth/services/auth-guard.service.ts b/example-app/app/auth/services/auth-guard.service.ts index d110bd753b..106eecb990 100644 --- a/example-app/app/auth/services/auth-guard.service.ts +++ b/example-app/app/auth/services/auth-guard.service.ts @@ -6,7 +6,9 @@ import { map, take } from 'rxjs/operators'; import * as AuthActions from '../actions/auth.actions'; import * as fromAuth from '../reducers'; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class AuthGuard implements CanActivate { constructor(private store: Store) {} diff --git a/example-app/app/auth/services/auth.service.ts b/example-app/app/auth/services/auth.service.ts index e8324f3d64..2478328d3a 100644 --- a/example-app/app/auth/services/auth.service.ts +++ b/example-app/app/auth/services/auth.service.ts @@ -3,7 +3,9 @@ import { Observable, of, throwError } from 'rxjs'; import { Authenticate, User } from '../models/user'; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class AuthService { constructor() {} diff --git a/example-app/app/books/books.module.ts b/example-app/app/books/books.module.ts index 3640361309..c1418b35d6 100644 --- a/example-app/app/books/books.module.ts +++ b/example-app/app/books/books.module.ts @@ -6,7 +6,6 @@ import { EffectsModule } from '@ngrx/effects'; import { ComponentsModule } from './components'; import { BookEffects } from './effects/book.effects'; import { CollectionEffects } from './effects/collection.effects'; -import { BookExistsGuard } from './guards/book-exists.guard'; import { FindBookPageComponent } from './containers/find-book-page.component'; import { ViewBookPageComponent } from './containers/view-book-page.component'; @@ -48,6 +47,5 @@ import { BooksRoutingModule } from './books-routing.module'; SelectedBookPageComponent, CollectionPageComponent, ], - providers: [BookExistsGuard], }) export class BooksModule {} diff --git a/example-app/app/books/guards/book-exists.guard.ts b/example-app/app/books/guards/book-exists.guard.ts index a17d05f8f5..223fb32128 100644 --- a/example-app/app/books/guards/book-exists.guard.ts +++ b/example-app/app/books/guards/book-exists.guard.ts @@ -13,7 +13,9 @@ import * as fromBooks from '../reducers'; * to inform the router's navigation process whether the route should continue * to activate this route. Guards must return an observable of true or false. */ -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class BookExistsGuard implements CanActivate { constructor( private store: Store, diff --git a/example-app/app/core/core.module.ts b/example-app/app/core/core.module.ts index db183569aa..4c6bf5b7d2 100644 --- a/example-app/app/core/core.module.ts +++ b/example-app/app/core/core.module.ts @@ -10,8 +10,6 @@ import { SidenavComponent } from './components/sidenav.component'; import { ToolbarComponent } from './components/toolbar.component'; import { MaterialModule } from '../material'; -import { GoogleBooksService } from './services/google-books.service'; - export const COMPONENTS = [ AppComponent, NotFoundPageComponent, @@ -26,11 +24,4 @@ export const COMPONENTS = [ declarations: COMPONENTS, exports: COMPONENTS, }) -export class CoreModule { - static forRoot() { - return { - ngModule: CoreModule, - providers: [GoogleBooksService], - }; - } -} +export class CoreModule {} diff --git a/example-app/app/core/services/google-books.service.spec.ts b/example-app/app/core/services/google-books.service.spec.ts index f1874689da..accc697cf6 100644 --- a/example-app/app/core/services/google-books.service.spec.ts +++ b/example-app/app/core/services/google-books.service.spec.ts @@ -9,10 +9,7 @@ describe('Service: GoogleBooks', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [ - { provide: HttpClient, useValue: { get: jest.fn() } }, - GoogleBooksService, - ], + providers: [{ provide: HttpClient, useValue: { get: jest.fn() } }], }); service = TestBed.get(GoogleBooksService); diff --git a/example-app/app/core/services/google-books.service.ts b/example-app/app/core/services/google-books.service.ts index 36d4ab5b7f..5865b8b63b 100644 --- a/example-app/app/core/services/google-books.service.ts +++ b/example-app/app/core/services/google-books.service.ts @@ -5,7 +5,9 @@ import { map } from 'rxjs/operators'; import { Book } from '../../books/models/book'; -@Injectable() +@Injectable({ + providedIn: 'root', +}) export class GoogleBooksService { private API_PATH = 'https://www.googleapis.com/books/v1/volumes';