Skip to content

Commit 9d7daf8

Browse files
committed
feat: add form array
1 parent 71cea8c commit 9d7daf8

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

frontend/src/angular/src/app/book-import/book-import.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<div class="base-container">
1818

1919
<form [formGroup]="bookForm">
20-
<button mat-flat-button color="primary" i18n="@@bookImportAddChapter">Add Chapter</button>
21-
<ng-container formArrayName="chapters">
20+
<button mat-flat-button color="primary" (click)="addChapter()" i18n="@@bookImportAddChapter">Add Chapter</button>
21+
<div class="chapters" formArrayName="chapters">
2222
@for(chaptersForm of chapters.controls;track chaptersForm) {
2323
<div class="chapter-container" [formGroup]="chaptersForm">
2424
<mat-form-field class="chapter-pages">
@@ -34,7 +34,7 @@
3434
</button>
3535
</div>
3636
}
37-
</ng-container>
37+
</div>
3838

3939
<input type="file" class="file-input"
4040
(change)="onFileSelected($event)" #fileUpload>

frontend/src/angular/src/app/book-import/book-import.component.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@
4141

4242
.chapter-container {
4343
display: flex;
44-
margin-top: 20px;
4544
align-items: center;
4645
}
4746

4847
.chapter-pages {
4948
width: 200px;
5049
margin: 10px;
50+
}
51+
52+
.chapters {
53+
margin-top: 20px;
5154
}

frontend/src/angular/src/app/book-import/book-import.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ export class BookImportComponent {
5454
}
5555

5656
protected removeChapter(chapterFg: FormGroup) {
57-
console.log(chapterFg);
57+
const chapterFormArray = this.bookForm.controls[FormGroupKey.chapters] as FormArray<FormGroup>;
58+
for(let i = 0;i < chapterFormArray.length;i++) {
59+
if(chapterFormArray.at(i) === chapterFg) {
60+
chapterFormArray.removeAt(i);
61+
}
62+
}
63+
}
64+
65+
protected addChapter(): void {
66+
const chapterFormArray = this.bookForm.controls[FormGroupKey.chapters] as FormArray<FormGroup>;
67+
chapterFormArray.push(this.createChapterGroupForm());
5868
}
5969

6070
protected createChapterGroupForm(): FormGroup {

0 commit comments

Comments
 (0)