Angular 2 route parameters

preview_player
Показать описание
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

Angular 2 Tutorial playlist

Angular 2 Text articles and slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

Tags
activatedroute angular2 params
activatedroutesnapshot
activatedroutesnapshot angular 2
activatedroutesnapshot get url
activatedroutesnapshot params
activatedroutesnapshot component
angular 2 pass parameter to route
angular 2 send parameter to component

In this video we will discuss passing parameters to routes in Angular. Let us understand this with an example. We want to make Employee Code on Employee List component clickable.

{ path: 'employees/:code', component: EmployeeComponent },

Next, in EmployeeListComponent, modify the [td] element that displays employee code to bind it to the route we created above using the routerLink directive as shown below.

[/a]

Explanation of the above code:
1. Notice in this example we are binding routerLink directive to an array.
2. This array is called link parameters array.
3. The first element in the array is the path of the route to the destination component.
4. The second element in the array is the route parameter, in our case the employee code.

getEmployeeByCode(empCode: string): Observable[IEmployee] {
}

Explanation of the above code:
1. This method takes employee code as a parameter and returns that employee object (IEmployee).
2. This method issues a GET request to the Web API service.
3. Once the Web API service returns the employee object, this mehod maps it to IEmployee type and returns it.

In one of our previous videos we have created EmployeeComponent to display employee details. When we created this component, we have hard coded employee data in the component itself. Now let's modify it

1. To retrieve employee details by calling the Angular EmployeeService method getEmployeeByCode() we created above.
2. This method calls the server side Web API service which retrieves that specific employee details from the database.
3. The employee code parameter is in the URL
4. To retrieve the parameter from the URL we are using the ActivatedRoute service provided by Angular
5. Since ActivatedRoute is provided as a service inject it into the constructor just like how we have injected EmployeeService

There are diiferent approaches to reterieve route parameters values. We will discuss all the different approaches and when to use what in our upcoming videos.

providers: [EmployeeService]
Рекомендации по теме
Комментарии
Автор

Today what i am only because of you. I am viewing every video you put here and enjoying. It's like a game of throne for me. When i came here i disable my ad blocked, but you deserve more.

khalidkhan
Автор

Hi, just one question.. From where do you get such deep knowledge in every programming field, be it Angular, SQL, C#, MVC, Web Forms, jQuery, Web API, Web Services, literally anything.. what is your source of knowledge.. it is really incredible. You have vast knowledge in every thing. I hope you answer this :)

microtech
Автор

I love your explanation, a average student like me will become a awesome developer because of your tutorial. Great job !!

Gamerthatpokemon
Автор

People like you are blessing! thank you for this! :)

satvik
Автор

One question: in 9:47, why did you not add [] after IEmployee? You did that previously in emplyeeList.component.

gauravoberoi
Автор

Thanks for the Angular 2 tutorial, I am learning a lot of things.

girishacharya
Автор

Hello sir.. You looks me like god of angular for people like me. .
Thank you.

TubeAnkur
Автор

I had a problem with the Employee Details until I changed the port number to the same port number as GetEmployees(). When I click on another code, I still get EMP101 details? What confuses me also is in the text you say to remove the "hash" but when I look at your video when you put in emp109, you have a "hash" in the url? Right now I'm getting an error for "employeeData". It says "employeeData not defined".

josephregallis
Автор

ngOnInit method is not firing when we change only route parameter (eg. employees/emp101 --> employees/emp102). This appears to be a bug but can't find solution to this. Could you please explain how to fix this.

learnwithanshika
Автор

I have applied it on web config. and put it on production server. But it is complaining about that bits. I am using framework 4.5.2 in .net and on production I have v4.0, Integrated, Filesystem pool. Am I doing something wrong?

bhavinjadav
Автор

Please upload tutorial on Forms and Validation Angular 2. your tutorials are awesome. Thank you a lot.

HorizonWave
Автор

I know you get alot of request but can you do one on angular animations. I can not get them to work with the angular CLI to work at all. Other wise I watch these vids as soon as they come out and refer to them often. These are better than an pluralsight course.

troybryantIII
Автор

Sir any more videos to come in for angular 2?

tejashreesawant
Автор

i write this code <a [routerLink]="['/employees', employee.code]">
{{employee.code | uppercase}}
</a>
and nothing change on td

mahmoudferaas
Автор

Sir, please make tutorials of WPF application. Please sir.

ChathurangaBasnayakeCSB
Автор

sir .. please make video tutorial on wpf or win form application too....

ProgrammingLover
Автор

i want to particular record details fetch but not correct out put pls tell me this my custom json when i concatinate id json givin erro not found
export class DetailsService {
public productId:any;

constructor(private _http:Http ){}

const here giving with id when i click all product comes thats not correctoutput

return this._http.get(url).map(
res=>{
const productinfo=res.json();
return productinfo;
})


}


}

mdhabib-xfdc
Автор

wherer i can get the source code???? !!!!

davehee
Автор

How do I use $compile in Angular 2 ? I am not able find any simple explanation on this, please cover this !!!

Gamerthatpokemon
Автор

Thank you very much sir for this angular tutorial, can you please make a video about auto-complete textBox in angular please sir

أمةالرحمان-تو