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

</textarea> </textarea>
</div> </div>
<button (click)="createBlogEntry(title.value, image.value, kategorie.value,menge.value, kommentar.value)"> <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> </button>


</form> </form>

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

}) })
export class AppComponent { export class AppComponent {


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

constructor(public fb: FormBuilder) { constructor(public fb: FormBuilder) {
this.entries = []; this.entries = [];
this.entries = initialEntries; this.entries = initialEntries;
get kategorieName() { get kategorieName() {
return this.registrationForm.get('kategorieName'); return this.registrationForm.get('kategorieName');
} }
title = 'Einkaufszettel';
entries: BlogEntry[] = [];
isSubmitted = false;
// Kategorien
Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];


/*########### Form ###########*/ /*########### Form ###########*/
registrationForm = this.fb.group({ registrationForm = this.fb.group({
this.entries.push(entry); 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 // Kategorie mit Drop Down Menu wählen
changeKategorie(e) { changeKategorie(e) {
console.log(e.value); console.log(e.value);

Loading…
Cancel
Save