Понятия не имею почему, но он внезапно перестал работать ... import
правильный, но не может увидеть navigate()
метод .. какие-нибудь идеи?
Каждый ответ на этот вопрос о пропущенном import
, но здесь есть правильный import
. navigate()
перестал работать в каждой части моего кода LOL, это только пример здесь. Есть идеи?
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import * as AuthActions from './auth.actions'
import * as UserDetailsActions from '../user/user-store/user.actions';
import * as StudentActions from '../../student/student-store/student.actions';
import { map, mergeMap, switchMap, switchMapTo, concatMapTo, withLatestFrom } from 'rxjs/operators';
import { Router } from '@angular/router';
@Injectable()
export class AuthEffects {
constructor(private actions$: Actions,
private router: Router) { }
@Effect()
authSignin = this.actions$
.pipe(
ofType(AuthActions.TRY_SIGNIN),
map((action: AuthActions.TrySignin) => {
return action.payload;
}),
switchMap((authData: any) => {
//here should be request to backend server with JWT
//set token and and username or user id
const userRetunedFromRequest = {
id: '5',
username: authData.username,
role: authData.role
}
localStorage.setItem('currentUser', JSON.stringify(userRetunedFromRequest));
//----------------------------------------------------
return [
new AuthActions.SigninUser,
new UserDetailsActions.GetUserDetailsById
]
})
);
@Effect({ dispatch: false })
loginRedirect = this.actions$
.pipe(
ofType(AuthActions.SIGNIN_USER),
map((action: AuthActions.SigninUser) => {
let url = this.navigateByUserRole();
this.router.navigate([`/${url}`]);
})
);
private navigateByUserRole(): string {
return JSON.parse(localStorage.getItem('currentUser')).role === 'PARENT' ? 'student' : 'teacher';
}
}