AngularJS Store
v3.0.0
v3.0.0
  • Introduction
  • Installation
  • Tutorials
    • Setup a store
    • Get the current state
    • Update the state
    • Get notified on state changes
    • Stop from receiving notifications
  • API Reference
    • NgStore
    • copy
    • dispatch
    • hook
Powered by GitBook
On this page
  1. Tutorials

Setup a store

PreviousTutorialsNextGet the current state

Last updated 6 years ago

Was this helpful?

CtrlK

Was this helpful?

To create a store we need to import and use the NgStore class.

counter-store.js
import NgStore from 'angularjs-store';

const initialState = { count: 0 };
const counterStore = new NgStore(initialState);

Make the store injectable by attaching it to AngularJS service. This will make our store available everywhere in our app. In the example below we named it CounterStore.

counter-store.js
import NgStore from 'angularjs-store';

angular
  .module('App', [])
  .factory('CounterStore', function CounterStore() {
    const initialState = { count: 0 };
    const counterStore = new NgStore(initialState);

    return counterStore;
  });