angular-store
  • @angular/store
  • State
  • Reducer
  • Action
  • Dipatch
  • Selector
  • MISCELLANEOUS
    • Methods
Powered by GitBook
On this page

State

To simply put, state is big object which will have some data as your normal object would.

Previous@angular/storeNextReducer

Last updated 6 years ago

let's take a simple example of object.

const state = {
    username: '@angular/store'
}

the key of above object represents . Each reducer will have a Key and a Initial state which will passed to state.

let's see how to state, implement in our application.

// this is our store module which takes Array of reducer classes,
// and some config. when logger is true, we will print console on state update
StoreModule.forRoot([UsernameReducer], {
  logger: true
})
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { StoreModule } from 'angular-store';

import { AppComponent } from './app.component';
import { UsernameReducer } from './app.compoenent.reducer';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    // this is our store module which takes Array of reducer classes,
    // and some config. when logger is true, we will print console on state update
    StoreModule.forRoot([UsernameReducer], {
      logger: true
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Reducer