Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2.  
  3. class Currency {
  4. id: number;
  5. name: string;
  6. value: number;
  7. }
  8.  
  9. class Saldo {
  10. id: number;
  11. balance: number;
  12. currency: Currency;
  13. }
  14.  
  15. class Account {
  16. id: number;
  17. number: number;
  18. saldos: Saldo[];
  19. }
  20.  
  21. @Component({
  22. selector: 'my-app',
  23. templateUrl: './app.component.html',
  24. styleUrls: ['./app.component.css']
  25. })
  26. export class AppComponent {
  27.  
  28. selectedSaldo;
  29.  
  30. saldo: Saldo;
  31. saldo2: Saldo;
  32. saldo3: Saldo;
  33.  
  34. account: Account;
  35. account2: Account;
  36.  
  37. accountList: Account[];
  38. saldoList: Saldo[];
  39.  
  40. result: number;
  41.  
  42. selectedAccount;
  43.  
  44. destinatedCurrency: Currency;
  45. currencies: Currency[];
  46. selected(){
  47. this.saldoList = this.selectedAccount.saldos;
  48. }
  49.  
  50. constructor() {
  51. this.initializeData();
  52. }
  53.  
  54. calculate(){
  55. this.result = (this.selectedSaldo.balance * this.selectedSaldo.currency.value)/this.destinatedCurrency.value;
  56. }
  57.  
  58.  
  59. initializeData() {
  60.  
  61. this.saldoList = [];
  62. this.accountList = [];
  63. this.currencies = [];
  64.  
  65. let currency = new Currency();
  66. currency.id = 0;
  67. currency.name = 'USD';
  68. currency.value = 3.42;
  69.  
  70. let currency2 = new Currency();
  71. currency2.id = 1;
  72. currency2.name = 'DOL';
  73. currency2.value = 4.22;
  74.  
  75. let currency3 = new Currency();
  76. currency3.id = 2;
  77. currency3.name = 'FRA';
  78. currency3.value = 2.12;
  79.  
  80. this.currencies.push(currency);
  81. this.currencies.push(currency2);
  82. this.currencies.push(currency3);
  83.  
  84. this.saldo = new Saldo();
  85. this.saldo.id = 0;
  86. this.saldo.balance = 150;
  87. this.saldo.currency = currency;
  88.  
  89. this.saldo2 = new Saldo();
  90. this.saldo2.id = 1;
  91. this.saldo2.balance = 120;
  92. this.saldo2.currency = currency2;
  93.  
  94. this.account = new Account();
  95. this.account.id = 0;
  96. this.account.number = 1231233213;
  97. this.account.saldos = [];
  98. this.account.saldos.push(this.saldo);
  99. this.account.saldos.push(this.saldo2);
  100.  
  101. this.saldo3 = new Saldo();
  102. this.saldo3.id = 2;
  103. this.saldo3.balance = 200;
  104. this.saldo3.currency = currency3;
  105.  
  106. this.account2 = new Account();
  107. this.account2.id = 1;
  108. this.account2.number = 3453454534;
  109. this.account2.saldos = [];
  110. this.account2.saldos.push(this.saldo3);
  111.  
  112. this.accountList.push(this.account);
  113. this.accountList.push(this.account2);
  114. }
  115.  
  116. }
  117.  
  118.  
  119. <h1>Drop Down</h1>
  120. <select [(ngModel)]="selectedAccount" (change)="selected()">
  121. <option *ngFor="let item of accountList" [ngValue]="item">{{item.number}}</option>
  122. </select>
  123.  
  124. <select [(ngModel)]="selectedSaldo">
  125. <option *ngFor="let item of saldoList" [ngValue]="item">{{item.currency.name}}</option>
  126. </select>
  127.  
  128. <select [(ngModel)]="destinatedCurrency">
  129. <option *ngFor="let item of currencies" [ngValue]="item">{{item.name}}</option>
  130. </select>
  131.  
  132.  
  133. <button (click)="calculate()">Przelicz na zł</button>
  134. {{ selectedSaldo.balance }}
  135.  
  136. {{ result }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement