Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { ActivatedRoute } from '@angular/router';
- import { ContactsService } from './contacts.service';
- @Component({
- selector: 'contacts-detail',
- template: `
- <h2>{{contact.name}}</h2>
- `
- })
- export class ContactsDetailComponent implements OnInit {
- constructor(private contactsService: ContactsService, private route: ActivatedRoute) {
- }
- ngOnInit() {
- this.contact = this.contactsService.getContact(this.route.snapshot.params.id);
- console.log('Fetching user', this.route.snapshot.params.id);
- }
- }
- ngOnInit() {
- this.sub = this.route.params.subscribe(params => {
- let id = +params['id'];
- this.contact = this.contactsService.getContact(id);
- });
- }
- import { Component, DoCheck } from '@angular/core';
- import { ActivatedRoute } from '@angular/router';
- import { ContactsService } from './contacts.service';
- @Component({
- selector: 'contacts-detail',
- template: `
- <h2>{{contact.name}}</h2>
- `
- })
- export class ContactsDetailComponent implements AfterViewChecked, DoCheck {
- constructor(private contactsService: ContactsService, private route: ActivatedRoute) {
- }
- ngDoCheck() {
- this.contact = this.contactsService.getContact(this.route.snapshot.params.id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement