Guest User

Untitled

a guest
Dec 12th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. {
  2. path: '',
  3. component: HomeComponent
  4. },
  5. {
  6. path: ':name',
  7. component: HomeComponent
  8. }
  9.  
  10. <h1 class="title">
  11. {{name ? name : "Noone"}}'s Home
  12. </h1>
  13.  
  14. <button routerLink="{{n}}" *ngFor="let n of names">{{n}}</button>
  15.  
  16. import { Component, OnInit } from '@angular/core';
  17. import { ActivatedRoute } from '@angular/router';
  18.  
  19. @Component({
  20. selector: 'app-home',
  21. templateUrl: './home.component.html',
  22. styleUrls: ['./home.component.scss']
  23. })
  24. export class HomeComponent implements OnInit {
  25.  
  26. constructor(private readonly _activatedRoute: ActivatedRoute) {
  27.  
  28. if (this._activatedRoute.snapshot.paramMap.has("name"))
  29. this.name = this._activatedRoute.snapshot.paramMap.get("name");
  30. }
  31.  
  32. public name: string;
  33.  
  34. public names = ["jack", "giorgia", "andrew", "alexia", "francesca", "luke"];
  35.  
  36. ngOnInit() {
  37. }
  38.  
  39. }
Add Comment
Please, Sign In to add comment