Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3. import { ContactsService } from './contacts.service';
  4.  
  5. @Component({
  6. selector: 'contacts-detail',
  7. template: `
  8. <h2>{{contact.name}}</h2>
  9. `
  10. })
  11. export class ContactsDetailComponent implements OnInit {
  12.  
  13. constructor(private contactsService: ContactsService, private route: ActivatedRoute) {
  14. }
  15.  
  16. ngOnInit() {
  17. this.contact = this.contactsService.getContact(this.route.snapshot.params.id);
  18. console.log('Fetching user', this.route.snapshot.params.id);
  19. }
  20. }
  21.  
  22. ngOnInit() {
  23. this.sub = this.route.params.subscribe(params => {
  24. let id = +params['id'];
  25. this.contact = this.contactsService.getContact(id);
  26. });
  27. }
  28.  
  29. import { Component, DoCheck } from '@angular/core';
  30. import { ActivatedRoute } from '@angular/router';
  31. import { ContactsService } from './contacts.service';
  32.  
  33. @Component({
  34. selector: 'contacts-detail',
  35. template: `
  36. <h2>{{contact.name}}</h2>
  37. `
  38. })
  39. export class ContactsDetailComponent implements AfterViewChecked, DoCheck {
  40.  
  41. constructor(private contactsService: ContactsService, private route: ActivatedRoute) {
  42. }
  43.  
  44. ngDoCheck() {
  45. this.contact = this.contactsService.getContact(this.route.snapshot.params.id);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement