Giter Club home page Giter Club logo

ng-store's Introduction

ng-store

Greenkeeper badge AngularJS store service base on store.js

origin store.js

How to User it

bower

bower install ng-store --save

and insert in HTML

npm

npm install ng-store --save

and then require it in you project

require('ng-store');

the mose important is require this module in Angular

angular
  .module('angularTApp', [
    'ngStore'
  ])

Provider

provider 2 method to config storage prefix and expiration

ngStoreProvider.prefix('test').exp(1000 * 5);

prefix

default:'st'

exp

default:3600 * 24 * 7

Document

ngStore.set('user', {name: 'marcus', likes: 'javascript',1000 * 60}); // store a object in 1 min
ngStore.get('user');    // {name: 'marcus', likes: 'javascript',1000 * 60}
ngStore.remove('user'); // marcus   return the key which been delete
ngStore.clear();        // [{key:'marcus'},value:{name: 'marcus', likes: 'javascript',1000 * 60}]     return a list which been delete
...

allmost like store.js's api

  • set(key,value,exp)
    • key{string}
    • value{any}
    • exp:[number],if no fill this argument,user default exp 3600 * 24 * 7

store the cache,accept and value except the function

  • get(key)
    • key{string}

return {value} or nuill

get the store ignore which not you store like some Google analysis and Baidu analysis

  • remove(key)
    • key{string}

return {object} which been delete

remove the cache

  • has(key)
    • key{string}

return {boolean}

check the cache exsit or not,ignore which not you store

  • forEach(func)
    • func{function}

like angular.forEach

  • getAll()

return the all key you own

  • clear()

clear the all cache ignore which not you store

Referrence

store.js

Additional method

$watch

watch a store and do some action when the value change lick $scope.$watch

only for communicate between the diffrent page (cros)

listen the onStorage Event that mean not work for store cookie

and there is a bug in IE:

IE will trigger the target window and it self,and chrome and firefox just trigger the target window

ngStore.$watch(key,watcher,[$scope])

var watcher = ngStore.$watch('user', function (newVal, oldVal) {
  console.log(newVal, oldVal);
}, $scope);

arguments

  • key{string}

the store key you want to watch

  • watcher{function}

a function,when the store change and run,the first arguments is old value,2nd is new value

  • $scope[Optional parameters]

if afferent this argument,it will automatically canceled when $scope $destroy I don't suggest you use this method in controller but in service

return{function}

return a function which can cancel this watcher like $scope.$watch

Build

grunt build

ng-store's People

Contributors

axetroy avatar greenkeeper[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

pratibhasharma5

ng-store's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.