@@ -19,23 +19,26 @@ import { Book, ChapterPages } from '../model/book';
19
19
import { MatToolbarModule } from '@angular/material/toolbar' ;
20
20
import { MatButtonModule } from '@angular/material/button' ;
21
21
import { FormArray , FormControl , FormGroup , ReactiveFormsModule , Validators } from '@angular/forms' ;
22
+ import { CommonModule } from '@angular/common' ;
22
23
23
24
enum FormGroupKey {
24
25
file = 'file' ,
25
- chapters = 'chapters'
26
+ chapters = 'chapters' ,
27
+ chapterStart = 'chapterStart' ,
28
+ chapterEnd = 'chapterEnd'
26
29
}
27
30
28
31
@Component ( {
29
32
selector : 'app-book-import' ,
30
33
standalone : true ,
31
- imports : [ MatIconModule , MatToolbarModule , MatButtonModule , ReactiveFormsModule ] ,
34
+ imports : [ MatIconModule , MatToolbarModule , MatButtonModule , ReactiveFormsModule , CommonModule ] ,
32
35
templateUrl : './book-import.component.html' ,
33
36
styleUrl : './book-import.component.scss'
34
37
} )
35
38
export class BookImportComponent {
36
39
protected bookForm = new FormGroup ( {
37
40
[ FormGroupKey . file ] : new FormControl < File | null > ( null , Validators . required ) ,
38
- [ FormGroupKey . chapters ] : new FormArray ( [ ] )
41
+ [ FormGroupKey . chapters ] : new FormArray ( [ this . createChapterGroupForm ( ) ] )
39
42
} ) ;
40
43
private destroyRef = inject ( DestroyRef ) ;
41
44
protected FormGroupKey = FormGroupKey ;
@@ -44,6 +47,17 @@ export class BookImportComponent {
44
47
45
48
constructor ( private documentService : DocumentService ) { }
46
49
50
+ get chapters ( ) {
51
+ return this . bookForm . controls [ FormGroupKey . chapters ] as FormArray < FormGroup > ;
52
+ }
53
+
54
+ protected createChapterGroupForm ( ) : FormGroup {
55
+ return new FormGroup ( {
56
+ [ FormGroupKey . chapterStart ] : new FormControl ( 0 , Validators . required ) ,
57
+ [ FormGroupKey . chapterEnd ] : new FormControl ( 0 , Validators . required )
58
+ } ) ;
59
+ }
60
+
47
61
protected logout ( ) : void {
48
62
console . log ( 'logout' ) ;
49
63
}
0 commit comments