|
|
@ -137,7 +137,7 @@ createBook() { |
|
|
Add a `form` variable and inject a `FormBuilder` service to the `book-list.component.ts` as shown below (remember add the import statement). |
|
|
Add a `form` variable and inject a `FormBuilder` service to the `book-list.component.ts` as shown below (remember add the import statement). |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
import { FormGroup, FormBuilder } from '@angular/forms'; |
|
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; |
|
|
|
|
|
|
|
|
form: FormGroup; |
|
|
form: FormGroup; |
|
|
|
|
|
|
|
|
@ -222,12 +222,13 @@ Open the `book-list.component.ts` and then create an array, named `bookTypeArr`: |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
//... |
|
|
//... |
|
|
form: FormGroup; |
|
|
booksType = Books.BookType; |
|
|
|
|
|
|
|
|
bookTypeArr = Object.keys(Books.BookType).filter( |
|
|
bookTypeArr = Object.keys(Books.BookType).filter( |
|
|
bookType => typeof this.booksType[bookType] === 'number' |
|
|
bookType => typeof this.booksType[bookType] === 'number' |
|
|
); |
|
|
); |
|
|
``` |
|
|
``` |
|
|
|
|
|
> It use the `booksType` field,please put the `bookTypeArr` defined below that line |
|
|
|
|
|
|
|
|
The `bookTypeArr` contains the fields of the `BookType` enum. Resulting array is shown below: |
|
|
The `bookTypeArr` contains the fields of the `BookType` enum. Resulting array is shown below: |
|
|
|
|
|
|
|
|
@ -293,6 +294,9 @@ This adds a save button to the bottom area of the modal: |
|
|
Then define a `save` method in the `BookListComponent`: |
|
|
Then define a `save` method in the `BookListComponent`: |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
|
|
|
//... |
|
|
|
|
|
import { ..., CreateUpdateBook } from '../../store/actions'; |
|
|
|
|
|
//... |
|
|
save() { |
|
|
save() { |
|
|
if (this.form.invalid) { |
|
|
if (this.form.invalid) { |
|
|
return; |
|
|
return; |
|
|
|