Install @frrri/ngxs-crud and its peer dependencies.
# @frrri/ngxs-crud
npm install @frrri/ngxs-crud --save
# dependencies
npm install @ngxs/store @ngxs-labs/data --save
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { NgxsModule } from '@ngxs/store';
import { NgxsDataPluginModule } from '@ngxs-labs/data';
import { EntitiesState } from './entities.state'; // <-- we will add this next
import { PostsState } from './posts.state'; // <-- we will add this next
@NgModule({
imports: [
HttpClientModule,
NgxsModule.forRoot([EntitiesState, PostsState], {
developmentMode: !environment.production
}),
NgxsDataPluginModule.forRoot(),
]
})
export class AppModule {}
import { PoststState } from './posts.state';
@CrudEntities({
name: 'entities',
children: [PostsState]
})
export class EntitiesState extends CrudEntitiesState { }
@CrudCollection({
name: 'posts'
})
export class PostsState extends CrudCollectionState { }
import { Store } from '@ngxs/store';
import { PostsState } from './posts.state';
@Component({ ... })
export class AppComponent {
constructor(private posts: PostsState) {}
getPosts(name: string) {
this.posts.getMany().toPromise();
}
}