0% found this document useful (0 votes)
15 views2 pages

comp5

computer notes

Uploaded by

jackmwexh1225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

comp5

computer notes

Uploaded by

jackmwexh1225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class TransferService {
transferAmount: number = 0;

constructor() { }

getTransferAmount() {
return this.transferAmount;
}

setTransferAmount(amount: number) {
this.transferAmount = amount;
}
}
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class WithdrawService {
withdrawAmount: number = 0;

constructor() { }

getWithdrawAmount() {
return this.withdrawAmount;
}

setWithdrawAmount(amount: number) {
this.withdrawAmount = amount;
}
}

import { NgModule } from '@angular/core';


import { Routes, RouterModule } from '@angular/router';
import { BalanceComponent } from './balance/balance.component';
import { TransferComponent } from './transfer/transfer.component';
import { WithdrawComponent } from './withdraw/withdraw.component';

const routes: Routes = [


{ path: '', redirectTo: '/balance', pathMatch: 'full' },
{ path: 'balance', component: BalanceComponent },
{ path: 'transfer', component: TransferComponent },
{ path: 'withdraw', component: WithdrawComponent }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

import { Component, OnInit } from '@angular/core';


import { Router } from '@angular/router';
import { BalanceService } from '../balance.service';
import { TransferService } from '../transfer.service';

@Component({
selector: 'app-transfer',
template: `
<h2>Transfer</h2>
<p>Transfer amount: {{ transferService.getTransferAmount() }}</p>
<input type="number" [(ngModel)]="amount">
<button (click)="setTransferAmount()">Set transfer amount</button>
<button (click)="transfer()">Transfer</button>
`
})
export class TransferComponent implements OnInit {
amount: number = 0;

constructor(
public balanceService: BalanceService,
public transferService: TransferService,
public router: Router
) { }

ngOnInit() { }

setTransferAmount() {
// Set transfer amount
this.transferService.setTransferAmount(this.amount);
}

transfer() {
// Transfer funds
const transferAmount = this.transferService.getTransferAmount();
this.balanceService.transfer(transferAmount);
this.transferService.setTransferAmount(0);
this.router.navigateByUrl('/balance');
}
}

You might also like