Created
September 20, 2018 13:46
-
-
Save rexar1988/91a29813edb9a1cfe4d46dfd848d4911 to your computer and use it in GitHub Desktop.
Angular: Url params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>adv works!</p> | |
<p>You advert is {{ id }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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