Skip to content

Instantly share code, notes, and snippets.

@rexar1988
Created September 20, 2018 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexar1988/91a29813edb9a1cfe4d46dfd848d4911 to your computer and use it in GitHub Desktop.
Save rexar1988/91a29813edb9a1cfe4d46dfd848d4911 to your computer and use it in GitHub Desktop.
Angular: Url params
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdvComponent } from './adv.component';
const routes: Routes = [
{
path: ':id', component: AdvComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AdvRoutesModule {}
<p>adv works!</p>
<p>You advert is {{ id }}</p>
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-adv',
templateUrl: './adv.component.html',
styleUrls: ['./adv.component.scss']
})
export class AdvComponent implements OnInit {
id: number;
constructor(private _route: ActivatedRoute) { }
ngOnInit() {
this.id = this._route.snapshot.params['id'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment