@ -308,16 +308,24 @@ Swagger has a nice UI to test APIs. You can try to execute the `[GET] /api/app/b
### Create the Books Page
It's time to create something visible and usable!
In this tutorial;
* [Angular CLI](https://angular.io/cli) will be used to create modules, components and services
* [NGXS](https://ngxs.gitbook.io/ngxs/) will be used as the state management library
* [Ng Bootstrap](https://ng-bootstrap.github.io/#/home) will be used as the UI component library.
* [Visual Studio Code](https://code.visualstudio.com/) will be used as the code editor (you can use your favorite editor).
#### Install NPM Packages
In this Angular Application, [Angular CLI](https://angular.io/cli) will be used to creating modules, components, services, etc. , [NGXS](https://ngxs.gitbook.io/ngxs/) will be used as state management and [Ng Bootstrap](https://ng-bootstrap.github.io/#/home) will be used as the UI library.
Open a terminal window and go to `angular` folder and then run `yarn` command for installing NPM packages:
```
yarn
```
Open a terminal window and go to `angular` folder and then run `yarn` command for installing packages.
#### BooksModule
Run the following command line for creating `BooksModule`
Run the following command line to create a new module, named `BooksModule`:
```bash
yarn ng generate module books --route books --module app.module
Books page works but you need some configuration for the application layout.
Let's start the coding.
>[Visual Studio Code](https://code.visualstudio.com/) will be used in this tutorial.
#### Routing
Open the `app-routing.module.ts` and replace `books`route to the below route.
Open the `app-routing.module.ts` and replace `books` as shown below:
```typescript
import { LayoutApplicationComponent } from '@abp/ng.theme.basic';-
@ -353,32 +357,30 @@ import { LayoutApplicationComponent } from '@abp/ng.theme.basic';-
},
```
If you would like to see your route on the navigation bar of `LayoutApplication`, you must add the `data` object with `name` property in your route.
>ABP themes have three layouts. These layouts are `LayoutApplication`, `LayoutAccount` and `LayoutEmpty`. [Check these layouts.](https://github.com/abpframework/abp/tree/dev/npm/ng-packs/packages/theme-basic/src/lib/components)
`LayoutApplicationComponent` configuration sets the application layout to the new page. If you would like to see your route on the navigation bar (main menu) you must also add the `data` object with `name` property in your route.
Replace the following code block to `books.actions.ts`.
Added a `get` method to get the list of books by performing an HTTP request to the related endpoint.
Replace `books.actions.ts` content as shown below:
```typescript
export class GetBooks {
@ -582,7 +531,9 @@ export class GetBooks {
}
```
Replace the next code block to `books.state.ts`.
#### Implement the BooksState
Open the `books.state.ts` and change the file as shown below:
```typescript
import { State, Action, StateContext, Selector } from '@ngxs/store';
@ -605,10 +556,6 @@ export class BooksState {
@Action(GetBooks)
get({ patchState }: StateContext<Books.State>) {
/* Suggestion:
You never subscribe to an observable here
and don't forget to return
*/
return this.booksService.get().pipe(
tap(books => {
patchState({
@ -618,11 +565,14 @@ export class BooksState {
);
}
}
```
>See the [Selectors on NGXS Document](https://ngxs.gitbook.io/ngxs/concepts/select#memoized-selectors)
* Added a `GetBooks` action that uses the `BookService` defined above to get the books and patch the state.
You ready to get books and list in the table.
>NGXS requires to return the observable without subscribing it, as done in this sample (in the get function).
#### BookListComponent
Modify the `book-list.component.ts` as shown below:
```typescript
import { Component, OnInit } from '@angular/core';
@ -651,16 +601,15 @@ export class BookListComponent implements OnInit {
this.loading = true;
this.store.dispatch(new GetBooks())
.subscribe(() => {
// This subscribe block runs when the action completed successfully
this.loading = false
};
}
}
```
>See the [Dispatching Actions](https://ngxs.gitbook.io/ngxs/concepts/store#dispatching-actions) and [Select](https://ngxs.gitbook.io/ngxs/concepts/select) on NGXS Document
>See the [Dispatching Actions](https://ngxs.gitbook.io/ngxs/concepts/store#dispatching-actions) and [Select](https://ngxs.gitbook.io/ngxs/concepts/select) on the NGXS documentation for more information on these NGXS features.
Copy next code block to `book-list.component.html`.
Replace `book-list.component.html` content as shown below:
```html
<divid="wrapper"class="card">
@ -695,15 +644,17 @@ Copy next code block to `book-list.component.html`.
</div>
</div>
```
> PrimeNG Table used in this component. See the [PrimeNG Table Document](https://www.primefaces.org/primeng/#/table)
> We've used [PrimeNG table](https://www.primefaces.org/primeng/#/table) used in this component.