Skip to content

Commit 32515fd

Browse files
author
Your Name
committed
NgRx - The Complete Guide
1 parent b2e19f2 commit 32515fd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/app/auth/auth.effects.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Injectable} from '@angular/core';
2+
import {Actions, createEffect} from '@ngrx/effects';
3+
4+
5+
@Injectable()
6+
export class AuthEffects {
7+
8+
constructor(private actions$: Actions) {
9+
10+
actions$.subscribe(action => {
11+
12+
if (action.type == '[Login Page] User Login') {
13+
14+
localStorage.setItem('user',
15+
JSON.stringify(action["user"]));
16+
}
17+
18+
19+
});
20+
21+
}
22+
23+
}

src/app/auth/auth.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as fromAuth from './reducers';
1212
import {authReducer} from './reducers';
1313
import {AuthGuard} from './auth.guard';
1414
import {EffectsModule} from '@ngrx/effects';
15+
import {AuthEffects} from './auth.effects';
1516

1617
@NgModule({
1718
imports: [
@@ -22,7 +23,7 @@ import {EffectsModule} from '@ngrx/effects';
2223
MatButtonModule,
2324
RouterModule.forChild([{path: '', component: LoginComponent}]),
2425
StoreModule.forFeature('auth', authReducer),
25-
EffectsModule.forFeature([])
26+
EffectsModule.forFeature([AuthEffects])
2627
],
2728
declarations: [LoginComponent],
2829
exports: [LoginComponent]

0 commit comments

Comments
 (0)