]>
Commit | Line | Data |
---|---|---|
3baf9be2 | 1 | import { Component, OnInit, OnDestroy } from '@angular/core' |
0626e7af C |
2 | import { ActivatedRoute } from '@angular/router' |
3 | import { AccountService } from '@app/shared/account/account.service' | |
4 | import { Account } from '@app/shared/account/account.model' | |
a51bad1a | 5 | import { RestExtractor } from '@app/shared' |
734a5ceb C |
6 | import { catchError, switchMap, distinctUntilChanged, map } from 'rxjs/operators' |
7 | import { Subscription } from 'rxjs' | |
0626e7af C |
8 | |
9 | @Component({ | |
170726f5 C |
10 | templateUrl: './accounts.component.html', |
11 | styleUrls: [ './accounts.component.scss' ] | |
0626e7af | 12 | }) |
3baf9be2 | 13 | export class AccountsComponent implements OnInit, OnDestroy { |
6b738c7a | 14 | account: Account |
0626e7af | 15 | |
734a5ceb C |
16 | private routeSub: Subscription |
17 | ||
0626e7af C |
18 | constructor ( |
19 | private route: ActivatedRoute, | |
a51bad1a C |
20 | private accountService: AccountService, |
21 | private restExtractor: RestExtractor | |
0626e7af C |
22 | ) {} |
23 | ||
24 | ngOnInit () { | |
734a5ceb C |
25 | this.routeSub = this.route.params |
26 | .pipe( | |
27 | map(params => params[ 'accountId' ]), | |
28 | distinctUntilChanged(), | |
29 | switchMap(accountId => this.accountService.getAccount(accountId)), | |
30 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) | |
31 | ) | |
32 | .subscribe(account => this.account = account) | |
33 | } | |
0626e7af | 34 | |
734a5ceb C |
35 | ngOnDestroy () { |
36 | if (this.routeSub) this.routeSub.unsubscribe() | |
0626e7af | 37 | } |
0626e7af | 38 | } |