Guest User

Untitled

a guest
Jul 5th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2. import { ROUTER_DIRECTIVES, ActivatedRoute, Router } from '@angular/router';
  3. import { AccountsService } from './accounts.service';
  4. import { Account } from './account.model';
  5.  
  6. @Component({
  7. directives: [ROUTER_DIRECTIVES],
  8. template: `
  9. <ul class="nav nav-tabs" #tabs>
  10. <li role="presentation" routerLinkActive="active">
  11. <a [routerLink]="['/accounts', currentAccount, 'account-statement']">Account statement</a>
  12. </li>
  13. <li role="presentation" routerLinkActive="active">
  14. <a [routerLink]="['/accounts', currentAccount, 'invoices']">Invoices</a>
  15. </li>
  16. <li role="presentation" routerLinkActive="active">
  17. <a [routerLink]="['/accounts', currentAccount, 'payments']">Payments</a>
  18. </li>
  19. <li role="presentation" routerLinkActive="active">
  20. <a [routerLink]="['/accounts', currentAccount, 'account-details']">Account details</a>
  21. </li>
  22. <li role="presentation" routerLinkActive="active">
  23. <a [routerLink]="['/accounts', currentAccount, 'taxes']">Taxes</a>
  24. </li>
  25. <li role="presentation" routerLinkActive="active">
  26. <a [routerLink]="['/accounts', currentAccount, 'budget']">Budget</a>
  27. </li>
  28. <li role="presentation" routerLinkActive="active">
  29. <a [routerLink]="['/accounts', currentAccount, 'payment-method']">Payment method</a>
  30. </li>
  31. </ul>
  32. `
  33. })
  34.  
  35. export class AccountComponent implements OnInit {
  36. public constructor(private accountsService: AccountsService,
  37. private route: ActivatedRoute,
  38. private router: Router) { }
  39.  
  40. private sub: any;
  41. private availableAccounts: IChosenOption[] = [];
  42. private currentAccount: number;
  43.  
  44. private showAccount(account: number) {
  45. this.router.navigate(['/accounts', account, 'account-statement', '')]);
  46. }
  47.  
  48. public ngOnInit() {
  49. this.accountsService.getAccounts()
  50. .subscribe((accounts: Account[]) => {
  51. this.availableAccounts = accounts.map((a: Account) => ({
  52. Value: a.ID,
  53. Label: a.Name
  54. }));
  55. });
  56. this.sub = this.route.params.map(params => params['id'])
  57. .subscribe((id: number) => {
  58. console.log(id);
  59. this.currentAccount = id;
  60. });
  61. }
  62.  
  63. public ngOnDestroy() {
  64. this.sub.unsubscribe();
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment