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

Comp

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)
22 views2 pages

Comp

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 AccountService {
balance = 5000;

withdraw(amount: number) {
if (amount <= this.balance) {
this.balance -= amount;
return true;
} else {
return false;
}
}

transfer(amount: number, recipient: string) {


if (amount <= this.balance) {
this.balance -= amount;
// TODO: Implement transfer to recipient
return true;
} else {
return false;
}
}

getBalance() {
return this.balance;
}
}

<h2>Balance</h2>

<p>Your current balance is: {{ balance }}</p>

<a routerLink="/withdraw">Withdraw</a>

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


import { AccountService } from '../account.service';

@Component({
selector: 'app-balance',
templateUrl: './balance.component.html',
styleUrls: ['./balance.component.css']
})
export class BalanceComponent implements OnInit {
balance: number;

constructor(private accountService: AccountService) {}

ngOnInit() {
this.balance = this.accountService.getBalance();
}
}
<h2>Withdraw</h2>

<form (ngSubmit)="submitForm()">
<div class="form-group">
<label for="amount">Amount:</label>
<input type="number" id="amount" name="amount" [(ngModel)]="amount"
class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">Withdraw</button>
</form>

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


import { AccountService } from '../account.service';
import { BalanceComponent } from '../balance/balance.component';

@Component({
selector: 'app-withdraw',
templateUrl: './withdraw.component.html',
styleUrls: ['./withdraw.component.css']
})
export class WithdrawComponent {
amount: number;

constructor(private accountService: AccountService, private balanceComponent:


BalanceComponent) {}

submitForm() {
if (this.accountService.with

You might also like