For a practical example, we will reuse the same CRUD sample implementation from the section CRUD sample implementation with DataTable. Start off by adding the ngrx dependencies for a Redux-based application:
npm install @ngrx/store @ngrx/core --save
First of all, we need to define a shape for the store. In real applications, most likely available employees and currently selected employee might be shared across several components. Hence the store could be defined as follows:
export interface AppStore {
employees: Employee[];
selectedEmployee: Employee;
}
Next, we need to define actions which consist of types and optional payloads.
The best practice is to create Action Creator Services encapsulating associated actions:
https://github.com/ngrx/ngrx.github.io/blob/master/store/recipes/actions/action_services.md
https://github.com/ngrx/ngrx.github.io/blob/master/store/recipes/actions/action_services.md
We will create the service CrudActions with four CRUD actions and associated action creators:
@Injectable()
export class CrudActions {
static LOAD_EMPLOYEES...