Nice explanation wrt Guards. But in employee exist scenario we will be calling get employees twice (one in Guards and another in its component )and it may affect the performance. correct me if I am wrong
Hi Venkat I am getting below error msg when i am writing this line of code "const employeeExists = this._employeeService.getEmployee(route.paramMap.get('Name')); //Instead of "Id" i used "Name" // Error msg:- error TS2554: Expected 0 arguments, but got 1. error TS2554: Expected 0 arguments, but got 1. 16 const employeeExists = !!this._employeeService.getEmployee(route.paramMap.get('Name'));
this is awesome, but Can you please tell me If I want to restrict a user from a specific HTML element / typescript method/ function inside the component(some functions/ elements should be accessible but some should not), thank you.
Bro you are using canActivate without lazyloading modules is there anyway to use with lazy load modules i am getting function gaurd is not found for lazy load modules i know if i declare them in main app. Module they will be laoded
Hello Gowtham - Both are route guards and are used for different use cases. CanDeactivate Guard, guards navigation away from the current route where as CanActivate Guard, guards navigation to a route. For example, canActivate guard is used to check if the user is authorised to access a specific route. Non admin users should not be able to access admin routes. This is one use case for canActivate guard. CanDeactivate Guard, guards navigation away from the current route. For example, if you have a data entry form and you want to protect accidentally navigating away from the form, so we do not lose the data enetered so far. This is one use case for CanDeactivate Guard. Hope this answers your question.
Hi sir, it is not working for me. I am getting error as Uncaught (in promise): TypeError: Cannot read property 'get' of undefined.can you help me..I am new to angular.