File tree 4 files changed +40
-5
lines changed 4 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -598,7 +598,7 @@ export const LESSONS = {
598
598
} ,
599
599
59 : {
600
600
id : 59 ,
601
- "description" : "How To Define the Store Initial State " ,
601
+ "description" : "How To Define the Store Initial AppState " ,
602
602
"duration" : "9:10" ,
603
603
"seqNo" : 10 ,
604
604
courseId : 4
Original file line number Diff line number Diff line change
1
+ import { createAction , props } from '@ngrx/store' ;
2
+ import { User } from './model/user.model' ;
3
+
4
+
5
+ export const login = createAction (
6
+ "[Login Page] User Login" ,
7
+ props < { user : User } > ( )
8
+ ) ;
9
+
10
+
11
+
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import {AuthService} from "../auth.service";
7
7
import { tap } from "rxjs/operators" ;
8
8
import { noop } from "rxjs" ;
9
9
import { Router } from "@angular/router" ;
10
+ import { AppState } from '../../reducers' ;
11
+ import { login } from '../auth.actions' ;
10
12
11
13
@Component ( {
12
14
selector : 'login' ,
@@ -20,7 +22,8 @@ export class LoginComponent implements OnInit {
20
22
constructor (
21
23
private fb :FormBuilder ,
22
24
private auth : AuthService ,
23
- private router :Router ) {
25
+ private router :Router ,
26
+ private store : Store < AppState > ) {
24
27
25
28
this . form = fb . group ( {
26
29
email : [ 'test@angular-university.io' , [ Validators . required ] ] ,
@@ -35,6 +38,27 @@ export class LoginComponent implements OnInit {
35
38
36
39
login ( ) {
37
40
41
+ const val = this . form . value ;
42
+
43
+ this . auth . login ( val . email , val . password )
44
+ . pipe (
45
+ tap ( user => {
46
+
47
+ console . log ( user ) ;
48
+
49
+ this . store . dispatch ( login ( { user} ) ) ;
50
+
51
+ this . router . navigateByUrl ( '/courses' ) ;
52
+
53
+ } )
54
+ )
55
+ . subscribe (
56
+ noop ,
57
+ ( ) => alert ( 'Login Failed' )
58
+ ) ;
59
+
60
+
61
+
38
62
}
39
63
40
64
}
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ import {
7
7
} from '@ngrx/store' ;
8
8
import { environment } from '../../environments/environment' ;
9
9
10
- export interface State {
10
+ export interface AppState {
11
11
12
12
}
13
13
14
- export const reducers : ActionReducerMap < State > = {
14
+ export const reducers : ActionReducerMap < AppState > = {
15
15
16
16
} ;
17
17
18
18
19
- export const metaReducers : MetaReducer < State > [ ] = ! environment . production ? [ ] : [ ] ;
19
+ export const metaReducers : MetaReducer < AppState > [ ] = ! environment . production ? [ ] : [ ] ;
You can’t perform that action at this time.
0 commit comments