Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.

Angular 2 - Mastering Google's Front-End Framework - Chapter 7 - Routing URL Parameters In Angular


Listen Later

Oftentimes when a programmer is routing their application they use the ID given to them by the database. Sometimes one will also be able to create an ID for an object and then store it in the database. To use these ids one must be able to get ids from the routes: or store them in cookies.

For the first example we will be using the Angular Router to be able to allow for one to get the parameters of the current url. This can be done like so. First one wants to import Angularjs Router. This is done with the following code.

import { ActivatedRoute } from '@angular/router';

Then ActivatedRoute will be passed into the constructor.

constructor(private route: ActivatedRoute) { }

The parameters to the current url can then be found using the following code.

let id  = this.route.snapshot.params.id;

This ID can be passed into the Http Service file to be used to retrieve different

files from the database.

---
This episode is sponsored by
· Anchor: The easiest way to make a podcast. https://anchor.fm/app
---
Send in a voice message: https://anchor.fm/javascript-news/message
Support this podcast: https://anchor.fm/javascript-news/support
...more
View all episodesView all episodes
Download on the App Store

Javascript News - A collection of audio articles aimed toward Full Stack Development with JS.By Javascript News