gsklee / ngStorage

localStorage and sessionStorage done right for AngularJS.
MIT License
2.33k stars 461 forks source link

Is any way to decorate ngStorage service? #215

Closed svit-ws closed 8 years ago

svit-ws commented 8 years ago

I need for extending ngStorage with location dependent keys: .decorator('$localStorage', function ($delegate, $location) { $delegate.gridState = function (state) { var key = 'grid-' + $location.url().slice(1); if (state) this[key] = state; return this[key]; }; return $delegate; }) but this creates also the "gridState" key in storage...

egilkh commented 8 years ago

If your only worry is getting .gridState in storage you can call it $gridState instead and ngStorage should ignore it on every $apply.

Ref: https://github.com/gsklee/ngStorage/blob/master/ngStorage.js#L177