File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed
frontend/src/angular/src/app/book-import Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 17
17
< div class ="base-container ">
18
18
19
19
< 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 ">
22
22
@for(chaptersForm of chapters.controls;track chaptersForm) {
23
23
< div class ="chapter-container " [formGroup] ="chaptersForm ">
24
24
< mat-form-field class ="chapter-pages ">
34
34
</ button >
35
35
</ div >
36
36
}
37
- </ ng-container >
37
+ </ div >
38
38
39
39
< input type ="file " class ="file-input "
40
40
(change) ="onFileSelected($event) " #fileUpload >
Original file line number Diff line number Diff line change 41
41
42
42
.chapter-container {
43
43
display : flex ;
44
- margin-top : 20px ;
45
44
align-items : center ;
46
45
}
47
46
48
47
.chapter-pages {
49
48
width : 200px ;
50
49
margin : 10px ;
50
+ }
51
+
52
+ .chapters {
53
+ margin-top : 20px ;
51
54
}
Original file line number Diff line number Diff line change @@ -54,7 +54,17 @@ export class BookImportComponent {
54
54
}
55
55
56
56
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 ( ) ) ;
58
68
}
59
69
60
70
protected createChapterGroupForm ( ) : FormGroup {
You can’t perform that action at this time.
0 commit comments