Questions tagged [angular-guards]
123 questions
3
votes
2 answers
Angular resolver observable completes too early
I am passing a subject as an observable from a service to a resolver. The service may complete the observable when an http request completes or when it finds that the data it needs is cached. In the second case, where the data is cached it looks…

Sibi John
- 475
- 6
- 22
3
votes
1 answer
Set default query params while routing
I've the following route config:
const routes: Routes = [
// another routes
{ component: UsersListComponent, path: 'users' }
];
I want to "automatically" include some default QUERY parameters when something route to this.
E.g.:
The route…

dev_054
- 3,448
- 8
- 29
- 56
3
votes
2 answers
Enable candeactivate for child component
Am working on an angular application, i need to show an alert message if the user leaves the page with unsaved changes while editing.
i have created and registered a candeactivate guard in routes for this which is working fine in parent component.…

mevr
- 1,075
- 3
- 14
- 32
3
votes
4 answers
Angular 6: Uncaught (in promise): Error: StaticInjectorError(AppModule)[RoleGuardService]
I want to use RoleGuard service in one of my Angular 6 project. I have created a file - 'role-guard.service.ts' under "_guards" folder. Now in the routes file, I have declared the same as below and try to implement the same. Please note, I have a…

Niladri Banerjee - Uttarpara
- 2,219
- 8
- 52
- 92
3
votes
1 answer
Check for existence of element in possibly to be loaded list in ngrx
I'm trying to build a sequence of RXJS commands in a guard, in order to achieve this result in a simple library (as in books) application :
Check in the Store
If the state is not loaded, trigger an action
Once it's loaded, filter the data to find…

jprivard
- 49
- 1
- 3
3
votes
1 answer
How to make guard subscribes to a long polling request of a service in Angular 2
I'm trying to make an angular 2 version of an old fashion application. There is a service that sends recurring request to a server to check if user is being logged in or not. The login guard will check the polling to see if the login session result(…

vuquanghoang
- 370
- 2
- 5
- 15
2
votes
1 answer
angular2: call canDeactivate for same route and component but different parameters
In my application, there are multiple links with the same route but with different queryParams and fragment.
for example, I have links…

Hamid Taebi
- 357
- 2
- 12
2
votes
1 answer
How to wait for server authorization in an Angular role guard?
In my application, the user logs in and receives a JWT, which is stored in local storage. After the user is authenticated, there's a following call to the server to determine the user's roles and functions (what pages they can visit).
My problem is…

romeozor
- 861
- 1
- 11
- 26
2
votes
1 answer
Auth guard prevents access even when user is already login
When user first login with their credentials, the auth guard allows the user to access the admin pages but once I refresh or go to another admin page, the auth guard will redirect me back to the client side page, stating that I do not have…

caslawter
- 631
- 1
- 6
- 11
2
votes
1 answer
Angular Universal: Get Store in Guard on Server-side using NgRx
I am running an Angular 9 Universal application that uses NgRx for state management.
I am also using ngrx-store-localstorage to persist the Store into the user's localStorage.
I am trying to check if user is loggedIn before accessing certain routes…

Simon Brami
- 159
- 1
- 10
2
votes
3 answers
Angular AuthGuard does not return UrlTree from inside subscription
I am trying to implement UrlTree to redirect user if guard fails.
this.authService.isAuthenticated() returns observable.
The following does not work but it does console false.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):…

Maihan Nijat
- 9,054
- 11
- 62
- 110
2
votes
2 answers
how to make angular response to http 401
I'm having a nodejs (express) as a server side and an angular 6 as client.In the server I have middlewear function that makes a session check. In case where the session is invalid or not exists, I would like to send a response to the client so that…

Guy E
- 1,775
- 2
- 27
- 55
2
votes
0 answers
Angular 7 Redirecting to last visited page
I'm building an Angular app in which I'd like to redirect the user to the last visited page he was at after logging in. The idea would be that if you are logged in, I will fetch from a local storage the last visited page (which will get updated on…

Rodrigo Martinez
- 913
- 3
- 13
- 29
2
votes
3 answers
Class 'AuthGaurd' incorrectly implements interface CanActivate
I am beginner and learning Angular From tutorials as i follow those tutorials and when i implement interface CanAcivate as he did in tutorial its show error
Class 'AuthGaurd' incorrectly implements interface 'CanActivate'.
Property 'canActivate'…

Ahmad Raza
- 758
- 7
- 26
2
votes
0 answers
Angular 7 Route Guards Still Change URL
My application cannot show a change in the url address screen. Right now, my application rests at localhost:4200/, and that's it. So I have taken the time to ensure that my navigation links disable the location change:

user1100412
- 699
- 1
- 10
- 22