Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { UserService } from '../services/user.service';
- import { User } from '../models/user';
- import { ActivatedRoute, ParamMap } from '@angular/router';
- import { Observable, BehaviorSubject } from 'rxjs';
- @Component({
- selector: 'app-user-page',
- templateUrl: './user-page.component.html',
- styleUrls: ['./user-page.component.css']
- })
- export class UserPageComponent implements OnInit {
- user$: Observable<User>;
- userId:number = null;
- subscriptionUserId$;
- subscriptionUser$;
- constructor(public userService:UserService, private route: ActivatedRoute) {
- this.subscriptionUserId$ = this.route.paramMap.subscribe((params : ParamMap)=> {
- this.userId = parseInt(params.get('userId'));
- });
- }
- ngOnInit() {
- this.user$ = this.userService.getUserById(this.userId);
- }
- ngOnDestroy(){
- if(this.subscriptionUserId$)
- this.subscriptionUserId$.unsubscribe();
- if(this.subscriptionUser$)
- this.subscriptionUser$.unsubscribe();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement