# Installation

## Getting started

Install @frrri/ngxs-crud and its peer dependencies.

```bash
# @frrri/ngxs-crud
npm install @frrri/ngxs-crud --save

# dependencies
npm install @ngxs/store @ngxs-labs/data --save
```

Set up NgxsModul&#x65;**,** NgxsDataPluginModule, and HttpClientModule in `app.module.ts`

```typescript
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 {}
```

Now add a **CrudEntitiesState** (acting as a parent to your entities) and your first **CrudCollectionState**:

{% tabs %}
{% tab title="entities.state.ts" %}

```typescript
import { PoststState } from './posts.state';

@CrudEntities({
    name: 'entities',
    children: [PostsState]
})
export class EntitiesState extends CrudEntitiesState { }
```

{% endtab %}

{% tab title="posts.state.ts" %}

```typescript
@CrudCollection({
    name: 'posts'
})
export class PostsState extends CrudCollectionState { }
```

{% endtab %}
{% endtabs %}

In your `app.component.ts` you can retrieve data from your API:

{% hint style="info" %}
We recommend using [Routing Instructions](https://bitflut.gitbook.io/frrri/ngxs-crud/usage/routing-instructions) to resolve data instead of calling posts.getMany() directly in your components.
{% endhint %}

```typescript
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();
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bitflut.gitbook.io/frrri/ngxs-crud/usage/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
