import { Component , Input , OnChanges , OnDestroy , SimpleChanges } from '@angular/core' ; import { User } from '../../../models/user' ; import { UserService } from '../../../services/user.service' ; import { ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; @ Component ( { selector : 'cmdb-user-compact' , templateUrl : './user-compact.component.html' , styleUrls : [ './user-compact.component.scss' ] } ) export class UserCompactComponent implements OnDestroy { private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; @ Input ( ) public user : User ; public userID : number ; @ Input ( 'userID' ) public set UserID ( id ) { this . userID = id ; if ( this . userID ) { this . userService . getUser ( this . userID ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( user ) => { this . user = user ; } ) ; } } public constructor ( private userService ) { } public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }