1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import {Component} from '@angular/core';
- import {initialEntries} from './components/blog-entry/initialEntries';
- import {BlogEntry} from './components/blog-entry/blog-entry';
- import {FormBuilder, Validators} from '@angular/forms';
- @Component({
- selector: 'app-root',
- templateUrl: 'app.component.html'
- })
- export class AppComponent {
-
- title = 'Einkaufszettel';
- entries: BlogEntry[] = [];
- isSubmitted = false;
- Kategorien: any = ['Lebensmittel', 'Spielwaren', 'Technik', 'Sonstiges'];
-
- constructor(public fb: FormBuilder) {
- this.entries = [];
- this.entries = initialEntries;
- }
-
- // Getter method to access formcontrols
- get kategorieName() {
- return this.registrationForm.get('kategorieName');
- }
-
- /*########### Form ###########*/
- registrationForm = this.fb.group({
- kategorieName: ['', [Validators.required]]
- });
- saveTask(value: any){
- console.log(value);
- }
-
- createBlogEntry(title: string, image: string, kategorie: string, menge: string, kommentar: string, ) {
- if (title && image && kommentar && kategorie) {
- const entry = new BlogEntry();
- entry.title = title;
- entry.image = image;
- entry.kategorie = kategorie;
- entry.menge = menge;
- entry.kommentar = kommentar;
- 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);
- this.kategorieName.setValue(e.target.value, {
- onlySelf: true
- });
- }
-
- /*########### Template Driven Form ###########*/
- onSubmit() {
- this.isSubmitted = true;
- if (!this.registrationForm.valid) {
- return false;
- } else {
- alert(JSON.stringify(this.registrationForm.value));
- }
-
- }
-
- }
|