1 import { Component, OnInit, OnDestroy } from '@angular/core'
2 import { ActivatedRoute } from '@angular/router'
3 import { AccountService } from '@app/shared/account/account.service'
4 import { Account } from '@app/shared/account/account.model'
5 import { RestExtractor } from '@app/shared'
6 import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators'
7 import { Subscription } from 'rxjs'
10 templateUrl: './accounts.component.html',
11 styleUrls: [ './accounts.component.scss' ]
13 export class AccountsComponent implements OnInit, OnDestroy {
16 private routeSub: Subscription
19 private route: ActivatedRoute,
20 private accountService: AccountService,
21 private restExtractor: RestExtractor
25 this.routeSub = this.route.params
27 map(params => params[ 'accountId' ]),
28 distinctUntilChanged(),
29 switchMap(accountId => this.accountService.getAccount(accountId)),
30 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
32 .subscribe(account => this.account = account)
36 if (this.routeSub) this.routeSub.unsubscribe()