Browse Source

V0.1d Implementierung Einträge löschen (alle und letzten)

master
Christian Greif 4 years ago
parent
commit
31bdc26861
2 changed files with 26 additions and 7 deletions
  1. 7
    1
      src/app/app.component.html
  2. 19
    6
      src/app/app.component.ts

+ 7
- 1
src/app/app.component.html View File

@@ -22,7 +22,13 @@
</textarea>
</div>
<button (click)="createBlogEntry(title.value, image.value, kategorie.value,menge.value, kommentar.value)">
Blog-Eintrag anlegen
Eintrag anlegen
</button>
<button (click)="deleteAllEntries()">
Alle Einträge löschen
</button>
<button (click)="deleteLastEntry()">
Letzten Eintrag Löschen
</button>

</form>

+ 19
- 6
src/app/app.component.ts View File

@@ -8,6 +8,11 @@ import {FormBuilder, Validators} from '@angular/forms';
})
export class AppComponent {

title = 'Einkaufszettel';
entries: BlogEntry[] = [];
isSubmitted = false;
Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];

constructor(public fb: FormBuilder) {
this.entries = [];
this.entries = initialEntries;
@@ -17,11 +22,6 @@ export class AppComponent {
get kategorieName() {
return this.registrationForm.get('kategorieName');
}
title = 'Einkaufszettel';
entries: BlogEntry[] = [];
isSubmitted = false;
// Kategorien
Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];

/*########### Form ###########*/
registrationForm = this.fb.group({
@@ -42,7 +42,20 @@ export class AppComponent {
this.entries.push(entry);
}
}

deleteAllEntries() {
console.log(this.entries.length);
const index: number = this.entries.length;
if (index !== -1) {
this.entries = this.entries.splice(index, 1);
}
}
deleteLastEntry() {
console.log(this.entries.length);
const index: number = this.entries.length;
if (index !== -1) {
this.entries.splice(index-1, 1);
}
}
// Kategorie mit Drop Down Menu wählen
changeKategorie(e) {
console.log(e.value);

Loading…
Cancel
Save