Angular Tutorial - 25 - Route Parameters

Angular Tutorial - 25 - Route Parameters

Codevolution

7 лет назад

382,544 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@vntmadan
@vntmadan - 24.05.2020 10:53

why did you not use this.departmentId = parseInt(this.route.snapshot.paramMap.get('id'));

Ответить
@wsxx69
@wsxx69 - 22.06.2020 01:40

can u enable auto-subtitles for this video?

Ответить
@dishantvashistha2038
@dishantvashistha2038 - 24.06.2020 17:42

Zabardust Master Ji

Ответить
@karthikeyanns843
@karthikeyanns843 - 19.07.2020 17:16

hey your CSS file is empty is the GIT HUB REPO, kindly provide it

Ответить
@viktorlernt6063
@viktorlernt6063 - 22.07.2020 16:08

Thank you very much, helped me a lot!

Ответить
@ayoubanbara1685
@ayoubanbara1685 - 08.08.2020 22:04

thanks, you have a good voice

Ответить
@GeorgeWurthmann
@GeorgeWurthmann - 06.09.2020 02:50

Thank you! Helped me alot!

Ответить
@riddhipatel2578
@riddhipatel2578 - 15.09.2020 15:57

Thanks for video i have learned a lot from this playlist

I have one doubt.. you have used navigate method i have done same with routerlink (dynamic binding [routerLink] ="['department', department.id]" )
Its working same

Could you please let me know what is difference between these two

Ответить
@someshnukala804
@someshnukala804 - 15.09.2020 22:06

Thank you so much sir.
Great explanation. Kudos

Ответить
@vik8860
@vik8860 - 28.09.2020 19:13

Can you use router to create a link that dynamically points to rest api in back end? for example in case of a put request?

Ответить
@sairammullapudi6658
@sairammullapudi6658 - 12.10.2020 11:33

What is the purpose of keyword snapshot

Ответить
@harkiratsingh9071
@harkiratsingh9071 - 16.11.2020 05:09

I am not able to click on angular mongodb etc please help me itsurgent

Ответить
@Federation1323
@Federation1323 - 02.02.2021 18:55

You saved my weeks)))

Ответить
@RastafarTV
@RastafarTV - 22.02.2021 21:58

Good video

Ответить
@houseservice636
@houseservice636 - 28.02.2021 02:28

What if you want to put the name instead of the id?

Ответить
@aheteshamshaikh9743
@aheteshamshaikh9743 - 16.03.2021 08:41

First of all thanks for this awesome tutorial, I have tried this code and it's working on localhost only, Not working on a live server. any idea?

Ответить
@alexandersantosablaza7033
@alexandersantosablaza7033 - 18.03.2021 11:01

Argument of type 'string | null' is not assignable to parameter of type 'strin
g'.
i used all your service tutorial from there add this

public employees: Array<IEmployee> = [];
public departmentId;
constructor(private _employeeService:EmployeeService, private _activeRoute:ActivatedRoute) { }

ngOnInit(): void {
let id = parseInt(this._activeRoute.snapshot.paramMap.get('id'));

this._employeeService
.getEmployees()
.subscribe(data => this.employees = data);
}

Ответить
@TheShbh2011
@TheShbh2011 - 19.03.2021 08:25

parseInt(this.route.snapshot.get('id') always get error but when removing parseInt no error comes but data not displayed after passing id in url , page not found open, but in console data comes

Ответить
@yosiefberhe4974
@yosiefberhe4974 - 04.04.2021 01:41

How do i route to a new page without the old contents on it?

Ответить
@ramuasan4141
@ramuasan4141 - 23.05.2021 20:59

department-detail.component.ts

Solution 1:
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';

export class DepartmentDetailComponent implements OnInit {
public departmentID: any

constructor(private router: Router, private route: ActivatedRoute) { }

ngOnInit(): void {
this.route.paramMap.subscribe((params: ParamMap) => this.departmentID = parseInt(params.get('id') || ''));
// or this.route.paramMap.subscribe((params: ParamMap) => this.departmentID = parseInt(params.get('id') || '{}'));
}

previous() {
let previousId = this.departmentID - 1
this.router.navigate(['/departments', previousId])
}

next() {
let nextId = this.departmentID + 1
this.router.navigate(['/departments', nextId])
}
}

Solution 2:
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';

export class DepartmentDetailComponent implements OnInit {
public departmentID: any

constructor(private router: Router, private route: ActivatedRoute) { }

ngOnInit(): void {
this.route.paramMap.subscribe((params : ParamMap) => {
let id: any = parseInt(params.get('id') || '')
// or let id: any = parseInt(params.get('id') || '{}')
this.departmentID = id
})
}

previous() {
let previousId = this.departmentID - 1
this.router.navigate(['/departments', previousId])
}

next() {
let nextId = this.departmentID + 1
this.router.navigate(['/departments', nextId])
}
}

Ответить
@souvikc37
@souvikc37 - 03.06.2021 18:20

Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.

let id = parseInt(this.route.snapshot.paramMap.get('id'));

Getting error. Can anyone help?

Ответить
@abdillahfahime6194
@abdillahfahime6194 - 26.07.2021 14:52

you helped me so much , many thanks for you man

Ответить
@ndmaru8518
@ndmaru8518 - 29.07.2021 14:27

Completely understand. Thank you!

Ответить
@mayankdhyani1787
@mayankdhyani1787 - 09.08.2021 22:03

your explanation is top-notch but the fake accent is bothering me

Ответить
@srinivaspatnala696
@srinivaspatnala696 - 03.09.2021 10:35

Thank you for the video. Great one

Ответить
@khaledmohsen2724
@khaledmohsen2724 - 06.09.2021 06:19

good tutorial awesome man

Ответить
@sridhars9161
@sridhars9161 - 15.09.2021 14:33

I'm getting an error as template parse error.

Ответить
@sridhars9161
@sridhars9161 - 15.09.2021 14:33

Can anyone help me out?

Ответить
@loco7051
@loco7051 - 25.09.2021 01:45

Gracias que compre mi tarjeta 1060 6GB antes de la crisis me salio en 4500 mxn

Ответить
@seemazanvar9323
@seemazanvar9323 - 27.10.2021 15:02

Please make series on Angular 12

Ответить
@Glowupy126
@Glowupy126 - 24.04.2022 03:40

It didn't work for me, I got {{departmentId}} dispalyed like this in the screen

Ответить
@johnlauricefarmaccount8014
@johnlauricefarmaccount8014 - 18.05.2022 10:19

thank you it really helps

Ответить
@gyanaranjanrout9389
@gyanaranjanrout9389 - 20.05.2022 13:15

in recent version we need to implement this....
this.route.paramMap.subscribe(params => {
this.departmentId = params.get('id')});

Ответить
@sreeramreddyvelagala6952
@sreeramreddyvelagala6952 - 17.06.2022 20:10

If anyone's facing a problem with this error:
Error: src/app/department-detail/department-detail.component.ts:17:23 - error TS2345: Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.

Use this:
parseInt(this.route.snapshot.paramMap.get('id') as string)

instead of this:
parseInt(this.route.snapshot.paramMap.get('id'))

can't explain the theory behind this, but it works for current versions

Ответить
@irenazlo5173
@irenazlo5173 - 27.06.2022 22:27

After this video i feel my iq growed for 10 more

Ответить
@pavak7539
@pavak7539 - 30.06.2022 07:06

Hello sir. I am getting an error saying Parameter 'department' implicitly has an 'any' type. If I put department: any, then its showing blank.
Please help.

Ответить
@AnonymousPandaPanda
@AnonymousPandaPanda - 27.07.2022 04:46

Thank you @Codevolution for this amazing series! Your explanation is very simple and clear!

I got an error in departmentDetails.components.ts file in
ngOnInit(): void {
let i = parseInt(this.route.snapshot.paramMap.get('id')) as number; //this line
this.deptId = i;
}

Error : Argument of type 'string | null' is not assignable to parameter of type 'string'.
Type 'null' is not assignable to type 'string'.

Could someone please help? Thanks in Advance!!!

Ответить
@X-AEA-12
@X-AEA-12 - 07.08.2022 01:01

How do you past the rest of the properties to display on the department detail component?

Ответить
@suvendubiswal6820
@suvendubiswal6820 - 19.09.2022 20:59

Accurate 100% that I was looking for... Thank you

Ответить
@thegamerz5034
@thegamerz5034 - 07.10.2022 00:22

Amazing content, thanks!

Ответить
@learnwithankit3582
@learnwithankit3582 - 10.10.2022 20:24

How to write that css?

Ответить
@PrasannaDangol
@PrasannaDangol - 19.12.2022 22:07

let id = JSON.parse(this.route.snapshot.paramMap.get('id')!);
this might help

Ответить
@abdullahhamzan2159
@abdullahhamzan2159 - 27.12.2022 12:00

I have problem router with params, can you help me to solve problem with message error "NG04014: Invalid configuration of route '/departement/:id': path cannot start with a slash"

Ответить
@harshamandloi394
@harshamandloi394 - 15.02.2023 15:14

can't display the department list code are same as you right

Ответить
@rameshmadara1
@rameshmadara1 - 27.02.2023 12:40

<3

Ответить
@MinimSan
@MinimSan - 05.04.2023 10:30

Does anyone knows how to change the parameters as name selected instead of the id? I have tried the following method with no error but but nothing shows.


onSelect(department) {
this.router.navigate(['/departments', department.name]);
}


public departmentId="";
ngOnInit() {
this.departmentId = this.route.snapshot.paramMap.get('name');
}

Ответить
@lxdzii
@lxdzii - 21.07.2023 05:56

i finally get it... this part took a little longer to understand!

Ответить
@venkateshak63
@venkateshak63 - 09.09.2023 07:36

for those who have error in : department-detail.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';

@Component({
selector: 'app-department-details',
template: `
<p>
department-details works!
</p>
<h3>Your selected department with id = {{ departmentId }}</h3>
`,
styles: [],
})
export class DepartmentDetailsComponent implements OnInit {
public departmentId: any;

constructor(private route: ActivatedRoute) {}

ngOnInit() {
this.route.paramMap.subscribe((params: ParamMap) => {
const idParam = params.get('id');
if (idParam !== null) {
let id = parseInt(idParam);
this.departmentId = id;
} else {
// Handle the case when 'id' is null
// You can set a default value or take appropriate action here.
}
});
}
}

Ответить
@_Rand0mStalker
@_Rand0mStalker - 20.08.2024 12:44

Dude, thank you for this useful video without “extra water”

Ответить