Angular Guard - How to Use Functional Router Guard

  Рет қаралды 7,865

Monsterlessons Academy

Monsterlessons Academy

Күн бұрын

Пікірлер: 58
@MonsterlessonsAcademy
@MonsterlessonsAcademy 3 ай бұрын
WATCH NEXT: Angular Interview Questions and Answers - Dominate Your Next Interview - kzbin.info/www/bejne/a3LCin6ii7yAhtEsi=2DCn7yspEAAJ2H6l
@Fischly007
@Fischly007 Жыл бұрын
Came back to this after seeing it a while ago, and it was exactly what I needed on this cloudy Wednesday (my dude) 👌
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Hope you enjoyed it!
@emmanuelU17
@emmanuelU17 Жыл бұрын
Brief and straight to the point
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Thank you!
@vadimr5847
@vadimr5847 Жыл бұрын
Clear and informative as always, Thank you.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it was helpful!
@bijum777
@bijum777 Жыл бұрын
Good job. I am becoming a super follower of your teaching. Keep posting more and more informative videos
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Thank you, I will
@rembautimes8808
@rembautimes8808 Жыл бұрын
Thanks - was stumped by this and appreciate your explanation
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it was helpful!
@mikhailsmirnov8539
@mikhailsmirnov8539 Жыл бұрын
Thanks a lot! The Monster is the best!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad you like my videos!
@chrisb3902
@chrisb3902 Жыл бұрын
Great video! I was unaware this changed for version 15!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad I could help!
@ellegre6546
@ellegre6546 Жыл бұрын
Thank you so much! I fixed my function and it works now.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it helps!
@jaredbecker3152
@jaredbecker3152 Жыл бұрын
I was struggling with this for a while and could not figure out what I was doing wrong and then you said "It must return an observable of type boolean" and then it clicked. I was just returning true or false based on a call I made to a service. Thanks so much for this!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it helped!
@user-cc8kb
@user-cc8kb Жыл бұрын
Thanks a lot for this video! Helped me
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
@g-luu
@g-luu Жыл бұрын
Great tutorial. How would you mock the service inside this guard function?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
I didn't try that yet.
@fireflysemanticsmedia6267
@fireflysemanticsmedia6267 Жыл бұрын
Awesome - Thank you so much!!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Glad it was helpful!
@fundevelopment5223
@fundevelopment5223 Жыл бұрын
The app crashes when I invoke router.navigate(['posts']) without showing errors , why?
@spacedust8061
@spacedust8061 Жыл бұрын
Thank you so much!
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
@kol4an721
@kol4an721 Жыл бұрын
Guys, please help I write registration and create guard and if I provide these guard in CanActivate to 2 components UserComponent and LoginComponent So my page have been freeze and nothing working Guard code: const loginGuard:CanActivateFn = () => { cont router = inject(Router); if(localStorage.getItem(‘token’) !== null) { router.navigate([‘user’]); } router.navigateByUrl(‘login’); return true; } What I doing wrong?
@11ujujz47
@11ujujz47 Жыл бұрын
You should return false after router.navigate
@riketscience
@riketscience 9 ай бұрын
You are my favourite explainer and I always come to you first to help my angular/rxjs journey. One thing on this occasion: please note that "guard" is pronounced like "hard", just swap the consonant. So sounds as if it is spelt like "gard". You can forget the silent "u". Stupid English! Keep up the great content :)
@MonsterlessonsAcademy
@MonsterlessonsAcademy 9 ай бұрын
Yeap English is difficult. I will try my best.
@riketscience
@riketscience 9 ай бұрын
@@MonsterlessonsAcademy the language of software you seem pretty much fluent! 👌 Right now I'm trying to let a guard be determined by the result of a login modal. Having a bad time trying to work out if it's even possible. So instead of routing to a login page, if not logged in the guard would hopefully intercept this, bring up a login modal, and then if login successful the canActivate would return true and carry the user on to their original required route. Possible? Argghhh!!!
@mikhailratner4649
@mikhailratner4649 Жыл бұрын
Thanks for the video! Can you elaborate on what you've said regarding the reason of Angulars Dev Team to switch to functional guards?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
It is only my assumptions but Angular team tries to make Angular easier(?) / similar compared to React. We got functional guards and standalone components. It looks like Angular goes in functional direction. If at some point we get functional components then it is React clone.
@mikhailratner4649
@mikhailratner4649 Жыл бұрын
​@@MonsterlessonsAcademy I guess I am not advanced enough to answer this question well, but what I know is that Angular's Dev Team wanted to get rid of module since 2017. It was useful back when Angular 2 dropped, but now it is not necessary anymore. Anyway, I find that standalone components definitely make it easier to structure apps and it makes more fun to work with Angular, which is a good thing for Angular developers and even better for those who are learning it.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
@@mikhailratner4649 I agree but my problem is that ngmodules are not deprecated so I can't be 100% sure that if I write new project or course to teach people I must tell them that this is the new way of writing ng apps.
@mikhailratner4649
@mikhailratner4649 Жыл бұрын
​@@MonsterlessonsAcademy I think you can confidently switch to Standalone components in your lessons, since it is the preferred way for the Dev Team and many other popular Angular Developers. There is no imminent need for the Angular Dev Team to deprecate the modules (maybe one time they will) but since it is easy to migrate a "module" app into a standalone app, I think most projects will make the switch.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
@@mikhailratner4649 Thanks for the info. I rechecked official standalone video and they said exactly that modules become optional.
@sarahibrahim8943
@sarahibrahim8943 Жыл бұрын
thank you so much
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Welcome 😊
@ThanHtutZaw3
@ThanHtutZaw3 10 ай бұрын
in functional guard , I don't get currentUser . Instead I only get undefined (always) .
@sergiodesousafilho
@sergiodesousafilho Жыл бұрын
obrigado, ajudou muito! monstro!
@gangadharkaja2132
@gangadharkaja2132 Жыл бұрын
Theme and Font Name Please?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Gruvbox. Monaco
@anutaNYC
@anutaNYC Жыл бұрын
Almost begs the question why not just use react at this point?! They are making angular more and more like react..
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
There are pros and cons. For example Angular supports ts out of the box which is why all libs are written with ts. In React it depends. Also Angular Material and CDK are supported with every update of Angular and we don't have similar alternative for React where you need to look for specific libs which are often abandoned.
@anutaNYC
@anutaNYC Жыл бұрын
@@MonsterlessonsAcademy I personally love angular and worked on it last 5 years but it seems they're really pushing for react and ife seen and coded using TS fr react, even though it seems to be very painful. Your videos are very helpful, thank you
@NH-yv7im
@NH-yv7im Жыл бұрын
Hi
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
Hello
@waleedsharif618
@waleedsharif618 Жыл бұрын
Are people still using Angular ? I beliebe nowadays its just Reactjs ?
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
They do. Just open any website with vacancies for a big city.
@waleedsharif618
@waleedsharif618 Жыл бұрын
@@MonsterlessonsAcademy even new github co pilot based on gpt4 was trained on reactjs…
@Almighty_Flat_Earth
@Almighty_Flat_Earth Жыл бұрын
Angular is the matured professional framework, it has simple syntax than react. React is hard to understand, the DX of react is horrible. React is a child play. When it comes to serious enterprise app development, Angular comes in glory. React has brought shame to JavaScript community by making web development unnecessarily complicated.
@Almighty_Flat_Earth
@Almighty_Flat_Earth Жыл бұрын
React js is a blasphemy to JavaScript community. React nonsense must be banned across world plane. This f library makes web development unnecessarily complicated. Angular is far better than svelte and react nonsense., because it leverages rxjs subscription, angular service make communication between sibling components much easier, developers know what exactly is happening. Svelte and react have confusing code. Developer experience matters.
@idontwhy3132
@idontwhy3132 Жыл бұрын
lol @ flat_earth, but true facts
@rudrakhuntia5583
@rudrakhuntia5583 Жыл бұрын
thank you so much.
@MonsterlessonsAcademy
@MonsterlessonsAcademy Жыл бұрын
You're welcome!
takeUntilDestroyed Angular New Way to Unsubscribe
5:22
Monsterlessons Academy
Рет қаралды 7 М.
Java Multithreading 4 - Wait Notify
6:26
Do Some Dev
Рет қаралды 24
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Angular Redux - NgRx Angular, NgRx store, NgRx Effects, NgRx selectors
30:31
Monsterlessons Academy
Рет қаралды 68 М.
Change Detection in Angular - You Project Is 20x Slower!
15:16
Monsterlessons Academy
Рет қаралды 74 М.
Angular unsubscribe, Angular async pipe, RxJS subscribe - Avoid Memory Leaks
11:29
Dynamic modal in Angular
31:20
Michael Olech Coding
Рет қаралды 172
Behaviorsubject vs Subject rxjs - What to Use?
7:02
Monsterlessons Academy
Рет қаралды 9 М.
Angular Signals: What? Why? and How?
27:08
Deborah Kurata
Рет қаралды 70 М.
Angular Signals vs RxJS - Reuse It Effectively
9:02
Monsterlessons Academy
Рет қаралды 5 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН