|
@@ -1,14 +1,55 @@
|
|
|
import { Component } from '@angular/core';
|
|
import { Component } from '@angular/core';
|
|
|
import { RouterOutlet } from '@angular/router';
|
|
import { RouterOutlet } from '@angular/router';
|
|
|
import { HeaderboxComponent } from './headerbox/headerbox.component';
|
|
import { HeaderboxComponent } from './headerbox/headerbox.component';
|
|
|
|
|
+import { IncomeComponent } from './income/income.component';
|
|
|
|
|
+import {NgFor} from '@angular/common';
|
|
|
|
|
+import { Income } from './incomes';
|
|
|
|
|
+import { Person } from './person';
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-root',
|
|
selector: 'app-root',
|
|
|
standalone: true,
|
|
standalone: true,
|
|
|
- imports: [RouterOutlet, HeaderboxComponent],
|
|
|
|
|
|
|
+ imports: [NgFor, RouterOutlet, HeaderboxComponent, IncomeComponent],
|
|
|
templateUrl: './app.component.html',
|
|
templateUrl: './app.component.html',
|
|
|
styleUrl: './app.component.css'
|
|
styleUrl: './app.component.css'
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
export class AppComponent {
|
|
export class AppComponent {
|
|
|
title = 'wbs-rechner-angular';
|
|
title = 'wbs-rechner-angular';
|
|
|
|
|
+
|
|
|
|
|
+ persons: Array<Person> = [];
|
|
|
|
|
+
|
|
|
|
|
+ calculateTotalIncome(person: any): number {
|
|
|
|
|
+ let totalIncome = 0;
|
|
|
|
|
+ for (const income of person.incomes) {
|
|
|
|
|
+ totalIncome += income.amount;
|
|
|
|
|
+ }
|
|
|
|
|
+ return totalIncome;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ addPerson() {
|
|
|
|
|
+ const newPerson = {
|
|
|
|
|
+ index: this.getHighestIndex(this.persons)+1,
|
|
|
|
|
+ incomes: []
|
|
|
|
|
+ };
|
|
|
|
|
+ this.persons.push(newPerson);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ deletePerson(index: number) {
|
|
|
|
|
+ this.persons = this.persons.filter(person => person.index !== index);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getHighestIndex(arr: any[]): number {
|
|
|
|
|
+ let highestIndex = 0;
|
|
|
|
|
+ for (const item of arr) {
|
|
|
|
|
+ if (item.index > highestIndex) {
|
|
|
|
|
+ highestIndex = item.index;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return highestIndex;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|