Angular Tutorial - 26 - paramMap Observable

  Рет қаралды 226,071

Codevolution

Codevolution

Күн бұрын

Пікірлер: 105
@shahzebchaudhary3236
@shahzebchaudhary3236 4 жыл бұрын
For those who are facing problem with a continuous increment and decrement and are not getting where and how to use 'if' statement: 1. First of all import the DepartmentList component in the DepartmentDetails component. 2. Import the DepartmentList component in app.module as well(as we have passed all the components through RouterComponent array) and add it in the Providers array. 3. Then create an instance of DepartmentListComponent in DepartmentDetails component. 4. I suggest using the button instead of anchor tags, as we have the 'disabled' attribute. Declare two boolean variables: Previous Next 5. Now you can use 'if else' in both the methods: goPrevious() { this.departmentId = this.departmentId - 1; if(this.departmentId > 1 ){ this.minLimit = false; this.maxLimit = false; this.router.navigate(['/departments',this.departmentId]); } else this.minLimit = true; } goNext() { this.departmentId = this.departmentId + 1; if(this.departmentId < this.departmentsComp.departments.length ){ this.maxLimit = false; this.minLimit = false; this.router.navigate(['/departments',this.departmentId]); } else this.maxLimit = true; }
@EvilInsideYEA
@EvilInsideYEA 2 жыл бұрын
You can also disable the buttons inside the subscribe field so that the previous button is already disabled when you click on the first entry and the next button is already disabled when you click on the last entry, which looks nice. ngOnInit(): void { this.route.paramMap.subscribe({ next: (params) => { let id = parseInt(params.get('id') as string); this.departmentId = id; if (id = _departmentListComponent.departments.length) { this.maxLimit = true; } }, }); } And then write the button methods like this so the button doesnt get disabled ahead of time. goPrevious() { let previousId = this.departmentId - 1; if (previousId = _departmentListCompoment.departments.length) { this.maxLimit = true; this.router.navigate(['/departmentList', nextId]); } else { this.minLimit = false; this.maxLimit = false; this.router.navigate(['/departmentList', nextId]); } } }
@stevemaster92
@stevemaster92 7 жыл бұрын
Great tutorial, sir! I am a newbie to Angular 5 and Typescript, but now I feel like an expert ;-) 3x thumps up for easy following, clear explanations, and hands-on examples! Can you please include forms (only if there's important things to discuss) and authentication in Angular in your next episodes?? With login/register forms, logout, password hashing, cookies, and other functions that are necessary. Thanks!
@haransarwan3719
@haransarwan3719 Жыл бұрын
For this who are getting " Argument of type 'string | null' is not assignable to parameter of type 'string' " USE the param statement like this : let id = parseInt(params.get('id') ||'{}'); This is for Angular 14 and above version users.
@rangabharath4253
@rangabharath4253 4 жыл бұрын
Hi, Awesome series. Change the method to remove negative numbers if we click previous button. Or you can disable the prev button goPrevious() { if (this.departmentId === 1) { let previousId = 1; this.router.navigate(['/departments', previousId]); } else { let previousId = this.departmentId - 1; this.router.navigate(['/departments', previousId]); } }
@fasikademelash4638
@fasikademelash4638 3 жыл бұрын
I got error on id, it is fixed by => let id=parseInt(params.get("id"))
@kotaiahbabu2486
@kotaiahbabu2486 3 жыл бұрын
How did you solve it?
@fasikademelash4638
@fasikademelash4638 3 жыл бұрын
@@kotaiahbabu2486 I already mention it
@kotaiahbabu2486
@kotaiahbabu2486 3 жыл бұрын
for me it wasn't working. I changed it to ( params.get('id'),||" ")) ; then it worked.
@unspoken_shutter
@unspoken_shutter 2 жыл бұрын
thanks
@soumyaranjansahoo439
@soumyaranjansahoo439 2 жыл бұрын
thanks
@Santoshthakur100
@Santoshthakur100 4 жыл бұрын
Sir, I learned Angular with the help of your video... Always follow and share to my friends... Thanks for everything.
@someshnukala804
@someshnukala804 4 жыл бұрын
No words to praise sir. Great tutorial. Thank you so much sir. Thanks a lot for the best explanation
@lexiaontube
@lexiaontube 6 жыл бұрын
he doesn;t show for SOME REASON: import { ParamMap } from '@angular/router'
@jayhey2577
@jayhey2577 6 жыл бұрын
Thank you
@kishanprajapati5381
@kishanprajapati5381 5 жыл бұрын
great you mentioned
@shadow_3213
@shadow_3213 5 жыл бұрын
import { Component, OnInit } from '@angular/core'; import { Router, ActivatedRoute, ParamMap } from '@angular/router'; @Component({ selector: 'app-department-detail', templateUrl: './department-detail.component.html', styleUrls: ['./department-detail.component.scss'] }) export class DepartmentDetailComponent implements OnInit { public departmendId; constructor(private route: ActivatedRoute, private router: Router) { } ngOnInit() { //let id = parseInt(this.route.snapshot.paramMap.get('id')); //this.departmendId = id; this.route.paramMap.subscribe((params: ParamMap) => { let id = parseInt(params.get('id')); this.departmendId = id; }); } goPrevious(){ let previousId = this.departmendId - 1; this.router.navigate(['/departments', previousId]); } goNext(){ let nextId = this.departmendId + 1; this.router.navigate(['/departments', nextId]); } }
@srinupotnuru9945
@srinupotnuru9945 4 жыл бұрын
thanks buddy
@varunteja8204
@varunteja8204 3 жыл бұрын
@@shadow_3213 jk
@mohit66552
@mohit66552 5 жыл бұрын
here id is increment continuously even if there is 4 dept. so once we reach at dept id 4 then it should stop of increment. also same for decrements otherwise its good
@vaibhavgautam3682
@vaibhavgautam3682 2 жыл бұрын
I tried this approach for five departments. Prev Next ngOnInit(){ this.route.paramMap.subscribe((params:ParamMap)=>{ let id=parseInt(params.get('id')||'{}') this.departmentId=id if(this.departmentId==1) this.minLimit=true if(this.departmentId==5) this.maxLimit=true }) } Prev(){ let previousId=this.departmentId-1 if(previousId>=1){ this.maxLimit=false this.router.navigate(['/departments',previousId]) } } Next(){ let nextId=this.departmentId+1 if(nextId
@markshibley7085
@markshibley7085 5 жыл бұрын
Excellent explanation of snapshot vs. paramMap. Thank you.
@ailespro_travels
@ailespro_travels 4 жыл бұрын
worked for me. best tutorial for dynamic routing
@misycode
@misycode 3 жыл бұрын
actually when I'm clicking on the next button it's not increasing the value rather instead of increasing it is incrementing the same value next to each other..... :( what's wrong with my plus operator?
@icasemobileservicecenter3293
@icasemobileservicecenter3293 5 жыл бұрын
why u skip when u create button ?
@bigpapa7332
@bigpapa7332 6 жыл бұрын
I need a little bit of help... where should I check for if id < 1, then Previous Button should get disabled or disappear. Then, the Next Button gets disabled on the last element of the array (departments.length()) ..as now it keeps going on the -+nth number. Oh yes, one more thing, just passing the id in depart detail doesn't make all sense. Id with depart name would have been more impressive. Thank you.
@adnankhuwaja1234
@adnankhuwaja1234 3 жыл бұрын
Same Question
@letscode1388
@letscode1388 2 жыл бұрын
Check it at the same time. If the I'd is less than 1 than assign it last value it contains
@rupambhattacharyya780
@rupambhattacharyya780 Жыл бұрын
How did u understand all these by yourself? Hats off
@rahulchowdhury1559
@rahulchowdhury1559 3 жыл бұрын
@Codevolution Can't we directly put the code inside ngOnInit in a function say updateRoute() and call this function in goPrevious() and goNext() after the route.navigate statement?
@Shakti_Kr_Singh
@Shakti_Kr_Singh 4 жыл бұрын
video at 03:45 snapshot works in angular 12 by default when we move to same view without using paramMap approach. Angular 12 is able to reuse the same component.
@NoshPatel
@NoshPatel 4 жыл бұрын
From which planet you belong to Bro? Because one Earth Angular 9 is released and 10 is not even fully planned. Good to see comment from other planet :)
@prathmeshnamdeo641
@prathmeshnamdeo641 4 жыл бұрын
Man, everything is nice, you explain nicely. But if you keep on clicking next or previous either one of them, they keep on increasing more than 5 and even decreases to negative values, what to do in such case.??????
@andrewyan883
@andrewyan883 6 жыл бұрын
Hi, somehow this video is listed before #25 on the KZbin playlist. Can you fix it?
@Codevolution
@Codevolution 6 жыл бұрын
Thanks for pointing it out. I fixed it :)
@andrewyan883
@andrewyan883 6 жыл бұрын
Thanks!
@srinivasvalekar9904
@srinivasvalekar9904 4 жыл бұрын
Brilliant explanation Vishwas! Thanks for these tutorials. I had a question , what if the ids are some random string? I know you wanted to explain about paramMap Observable, I was curious on how to solve this kind of problem.
@vinodhkumar457
@vinodhkumar457 7 жыл бұрын
Hi sir, please do on angular authentication, authorisation..
@HongKimhia
@HongKimhia 5 жыл бұрын
Excellent explanation thank you very much
@alagudrem
@alagudrem 6 жыл бұрын
Hi this is great article. Why you are using let previousID = this.currencyid -1; instead of this.currencyid = this.currencyid-1; is there any reason behind that ? could you please explain ?
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Very useful tutorial
@shujunhan8294
@shujunhan8294 4 жыл бұрын
millions of thanks to you.
@rod82921
@rod82921 4 жыл бұрын
if you press previous many times the id is going negative, pressing next the same, never stop, how you can stop the id going further from the departments lenght arrays???
@rahulsaraf6815
@rahulsaraf6815 4 жыл бұрын
In the methods goNext and goPrevious, we can simply assign this.departmentId to the next/previous id. This will get updates in the view as well, at the time of execution of this function itself. I tried this out and worked fine without having to use paramMap Observable - goPrevious() { let previousId = this.departmentId - 1; this.router.navigate(['/departments',previousId]); this.departmentId = previousId; } goNext() { let nextId = this.departmentId + 1; this.router.navigate(['/departments',nextId]); this.departmentId = nextId; }
@reduser77
@reduser77 4 жыл бұрын
could you explain why the router doesn't create new component when extracting the id from the snapshot ?
@harshavardhanreddy1907
@harshavardhanreddy1907 2 жыл бұрын
Hi, when i am clicking next button instead of incremen number is adding next to selected id if i add 2 for next button it is placing 2 beside selected id how can i resolve this problem. for example, i selected 3 when i am pressing next it is going to 31 when i press next one more time it is going to 311 like this..
@manishasony4998
@manishasony4998 2 жыл бұрын
I have one doubt, you said if we navigate back if cmp already present in angular it will reuse and ngOnInit() should not called right..so it recommended to do not use snapshot, but then again you are defining parammap observable in ngonInit where that method is not called then how param map observable code inside ngonInit method work
@ignitesofthelp
@ignitesofthelp 5 жыл бұрын
react gives easy solution for this approach. both are good, though.
@amanullahahmadzai7447
@amanullahahmadzai7447 4 жыл бұрын
Thank you very much Sir for your tutorials you have explained in very good manner bur I can't work after 25 because every time it gives me errors !!! by the way once again thanks . Bien Cordialement
@Santoshthakur100
@Santoshthakur100 4 жыл бұрын
I did not stand ActivatedRoute in angular... Can you please explain lil more about it. Question is: While changing the route I want to show particular common button on route change. Hope you understand .... Plz explain
@doktor_faust
@doktor_faust 6 жыл бұрын
I didn't really get the cons of using the observable map always. Why would you use the route snapshot, if the observable strategy works better?
@namikenzi9862
@namikenzi9862 6 жыл бұрын
For performance. If you want to preserve the component's state and not update it.
@themanthis837
@themanthis837 6 жыл бұрын
How comes this is not displayed as a link ? Next
@abhishekkumawat8353
@abhishekkumawat8353 6 жыл бұрын
If you're talking about the underline and the blue color, it's probably because of the absence of href attribute in the tag.
@kennethadrianbuenavista9570
@kennethadrianbuenavista9570 5 жыл бұрын
If you're talking about the underline and the blue color again he might have some css added to the tag.
@rishav00a
@rishav00a 5 жыл бұрын
because we are using onclick method there, there is no use of tag you can perform the same task using another tags like Next as well.
@konadeepak9443
@konadeepak9443 4 жыл бұрын
Will it be helpful if we update Id everytime we go in to Next and Previous methods
@shravilpotdar
@shravilpotdar 6 жыл бұрын
For me, previous button is not working and the next button is even accessing the ids beyond the number of elements in the list. Any solution?
@jayhey2577
@jayhey2577 6 жыл бұрын
previous id not always current id -1
@abhishekkumawat8353
@abhishekkumawat8353 6 жыл бұрын
I think, by previous id, he does not mean 'the previously visited id', instead the previous id of the current id in the list. This way we do not have to go back to the departments route to click on other department, we can just click next to see the next department, and previous as well.
@perujagan4840
@perujagan4840 5 жыл бұрын
It is. If Id is 1 then disable previous
@anuragsekhri2315
@anuragsekhri2315 4 жыл бұрын
let we select the last department now after selecting it if we click next it updates to the department id + 1 even if that department not exist how to solve this?
@anubhavkaushik7340
@anubhavkaushik7340 6 жыл бұрын
Hi, We are not facing the issue that you told About the snapshot approach....our URL as well as view both getting updated with out any issue....with previous approach also with out using ParamMap Observable....is there something that we are missing??
@ToDeoS
@ToDeoS 6 жыл бұрын
You should have the issue with the snapshot approach.... the url shouldnt update lol something is wrong
@nishantmalik1982
@nishantmalik1982 5 жыл бұрын
mine is also working fine too ….only change I made is in both methods is assigning of calculated id back to departmentIdonPrevious(){ let previousId = parseInt(this.customerId) - 1; this.customerId = previousId; //console.log("Value of previousId :" +previousId); this.router.navigate(['/customer',previousId]);}onNext(){ let nextId = parseInt(this.customerId) + 1; this.customerId = nextId; //console.log("Value of nextId :" +nextId); this.router.navigate(['/customer',nextId]);}
5 жыл бұрын
I was having a problem than when clicking next the changes were not reflecting, I'm assuming the compiling was not working, because I had to comment all the lines from goNext and goPrevious and uncomment one by one for the changes to start to show up. I had console.logs on the methods and were not reflecting until I did this.
@jyothisrilakamsani119
@jyothisrilakamsani119 4 жыл бұрын
How can I typecast string to date exact error is like cannot assign string to date. Could u please help
@rahi3139
@rahi3139 4 жыл бұрын
But there is a problem when we click on the next the value of id is increased after six as well but we have only six departemntids
@mohammadamir4756
@mohammadamir4756 3 жыл бұрын
@Codevolution! what if I want to pass an OBJECT instead id??
@HolyHarmonyOfficial
@HolyHarmonyOfficial 6 жыл бұрын
there are no subtitles after the 26th tutorial. There is a little effect I learn, could you add the subtitles
@trdngy8230
@trdngy8230 5 жыл бұрын
Why do not just simply update departmentId after every time goPrevious or goNext?
@sajansjoseph
@sajansjoseph 5 жыл бұрын
He is teaching Routing.... Not click event...
@RamKumar91221
@RamKumar91221 5 жыл бұрын
What if ID is a 'string' not an 'int'.. How can we navigate using previous and next buttons? @Codevolution
@ahmedfarag569
@ahmedfarag569 6 жыл бұрын
Tell me please how to pass the data of the component i've clicked on to the details component.
@ai.aspirations
@ai.aspirations 5 жыл бұрын
awesome tutorial
@ankurshukla8588
@ankurshukla8588 6 жыл бұрын
if i am clicking continuously, why the click counts are increasing ?
@ashfaqhussain761
@ashfaqhussain761 8 ай бұрын
sir the one which you told is activatedroute can be changed but we are unable to change it it's getting error you taught wrong thing in this video
@himanshu6823
@himanshu6823 6 жыл бұрын
But in this last part of video when we use arrow function and do next that also shows all record which is not in file or detail.
@jasondaniel5387
@jasondaniel5387 4 жыл бұрын
clear explanation
@umutacer01
@umutacer01 6 жыл бұрын
Please open auto subtitles :)
@kuldeepkodi5955
@kuldeepkodi5955 5 жыл бұрын
My code is working just with snapshot.. even without using paramMap. @Codevolution !?
@Anilkumar-lg9vy
@Anilkumar-lg9vy 5 жыл бұрын
How to display the department name in department detail
@akhilganne4178
@akhilganne4178 3 жыл бұрын
Not working with current angular
@TeluguCartoonist
@TeluguCartoonist 6 жыл бұрын
Previous id goes to minus values
@this_wind
@this_wind 5 жыл бұрын
again forgot to unsubscribe in large applications, this can lead to tangible memory leaks
@Santoshthakur100
@Santoshthakur100 4 жыл бұрын
If we are not unsubscribe , how can we deduct memory leaks issue in the project.... Plz reply soon
@Maxgautphotographe
@Maxgautphotographe 6 жыл бұрын
Instead of reading the value in the url... why you don't just do this : goPrevious(){ let previousId = this.departmentId - 1; *this.departmentId = previousId;* this.router.navigate(['/departments', previousId]); } goNext(){ let nextId = this.departmentId + 1; *this.departmentId = nextId;* this.router.navigate(['/departments', nextId]); } it will change the value of the departementId inside the method... and not doing the change in the ngOnInit(), maybe it was just to introduce the paramMap but...
@ToDeoS
@ToDeoS 6 жыл бұрын
What if some1 is to navigate by changing the url? Not many users would do that but in case if there is, your method won't work.
@seenuvasanv
@seenuvasanv 7 жыл бұрын
Thanks
@androiddevthings
@androiddevthings 6 жыл бұрын
Can you activate spanish subtitle for all videos? Thanks :)
@varunkarthikeyan5094
@varunkarthikeyan5094 5 жыл бұрын
can you give better easy project type lesson in angular and link me tag
@manishasony4998
@manishasony4998 2 жыл бұрын
Please clear this doubt
@vinodkumar19801
@vinodkumar19801 6 жыл бұрын
good
@pavanTY
@pavanTY 2 жыл бұрын
for whose who's value are not updating after calling gonex t() and goprevious(), inside both the function call this.ngOnInt(); it will work
@kelolettek3927
@kelolettek3927 3 жыл бұрын
english sub please.... difficult to understand a bit ! .....
@adamhamdi9210
@adamhamdi9210 Жыл бұрын
great $
@17001045jv
@17001045jv 6 жыл бұрын
Subtitles?
@geomukkath5373
@geomukkath5373 3 жыл бұрын
Angular routes are too much to take in.
@amirbennasr5030
@amirbennasr5030 5 жыл бұрын
why you dont work with html why always template ? thank you
@icasemobileservicecenter3293
@icasemobileservicecenter3293 5 жыл бұрын
why u skip when u create button ?
@efegfg
@efegfg 4 жыл бұрын
Please open auto subtitles :)
@icasemobileservicecenter3293
@icasemobileservicecenter3293 5 жыл бұрын
why u skip when u create button ?
Angular Tutorial - 27 - Optional Route Parameters
7:41
Codevolution
Рет қаралды 181 М.
What is Observable | Observables | Angular 12+
14:16
procademy
Рет қаралды 161 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
Angular Resource API - Everything You Have To Know (so far)
27:58
Decoded Frontend
Рет қаралды 17 М.
Angular Tutorial - 25 - Route Parameters
9:56
Codevolution
Рет қаралды 379 М.
Angular Tutorial - 24 - Wildcard Route and Redirecting Routes
7:31
Codevolution
Рет қаралды 285 М.
Angular v19 Developer Event
22:54
Angular
Рет қаралды 70 М.
Angular Tutorial - 23 - Routing and Navigation
12:51
Codevolution
Рет қаралды 932 М.
Promises vs Observables - Angular (Tutorial #30)
15:44
Nisha Singla
Рет қаралды 94 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 110 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН