Diskussionsthread zur Schulung #1
Replies: 17 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
describe('In der Mathematik', () => {
// Arrange
let summand: number;
beforeEach(() => {
summand = 1;
});
it('soll 1 + 1 immer 2 sein', () => {
// Act
const result = summand + 1;
// Assert
expect(result).toBe(2)
});
}); |
Beta Was this translation helpful? Give feedback.
-
import { Injectable } from '@angular/core';
import { Book } from './book';
@Injectable({
providedIn: 'root'
})
export class BookRatingService {
readonly minRating = 1;
readonly maxRating = 5;
rateUp(book: Book): Book {
if(book.rating >= this.maxRating) {
return book;
}
return {
...book,
rating: book.rating + 1
}
}
rateDown(book: Book): Book {
const rating = Math.max(book.rating - 1, this.minRating);
return {
...book,
rating
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Hausaufgabe (für Donnerstag)
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
import { NgForOf } from '@angular/common';
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-rating',
standalone: true,
imports: [NgForOf],
template: '<span *ngFor="let star of stars">✴️</span>',
})
export class RatingComponent {
stars: number[] = [];
@Input()
public set rating(value: number) {
this.stars = new Array(value);
}
} |
Beta Was this translation helpful? Give feedback.
-
Freiwillige Hausaufgabe: Buttons disablen (für Freitag)Deaktiviere die Buttons in der Ansätze:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
🎮 NEU: RxJS PlaygroundDu kannst dir entweder
cd rxjs-playground
npm install
ng serve |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
<form>
<div class="form-group">
<label for="isbn">ISBN</label>
<input type="text" class="form-control" id="isbn">
@if (false) {
<div class="feedback-error">Die ISBN ist ungültig!</div>
}
</div>
<div class="form-group">
<label for="title">Titel</label>
<input type="text" class="form-control" id="title">
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea class="form-control" id="description"></textarea>
</div>
<button type="submit" class="btn btn-primary mb-4">Erstellen</button>
</form>
|
Beta Was this translation helpful? Give feedback.
-
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
import { Book } from '../shared/book';
@Component({
selector: 'app-book-create',
standalone: true,
imports: [ReactiveFormsModule],
templateUrl: './book-create.component.html',
styleUrl: './book-create.component.scss'
})
export class BookCreateComponent {
bookForm = new FormGroup({
isbn: new FormControl('', {
nonNullable: true,
validators: [Validators.required, Validators.minLength(3)]
}),
title: new FormControl('', {
nonNullable: true,
validators: [Validators.required]
}),
description: new FormControl('', {
nonNullable: true
})
});
c = this.bookForm.controls;
isInvalid(control: FormControl) {
return control.invalid && control.touched;
}
// TODO:
// hasError(control: FormControl, errorCode: string): boolean
submitForm() {
const newBook: Book = {
...this.bookForm.getRawValue(),
rating: 1,
price: 1
}
// TODO!
// 1. Erzeuge ein Event mit dem Namen create – Payload: Book
// 2. Versende das Event
// 3. Subscribe dich auf das Event im Dashbard
// 4. Füge das Buch dem Array hinzu (immutable)
this.bookForm.reset();
}
} <form [formGroup]="bookForm" (ngSubmit)="submitForm()">
<div class="form-group">
<label for="isbn">ISBN</label>
<input [formControl]="c.isbn" type="text" class="form-control" id="isbn">
@if (isInvalid(c.isbn)) {
<div class="feedback-error">Die ISBN ist ungültig!</div>
}
</div>
<div class="form-group">
<label for="title">Titel</label>
<input [formControl]="c.title" type="text" class="form-control" id="title">
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea [formControl]="c.description" class="form-control" id="description"></textarea>
</div>
<button [disabled]="bookForm.invalid" type="submit" class="btn btn-primary mb-4">Erstellen</button>
</form> |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hier können wir während des Workshops Links und Codeschnipsel teilen.
Beta Was this translation helpful? Give feedback.
All reactions