agrublev / angularlocalstorage Goto Github PK
View Code? Open in Web Editor NEWThe simplest angular localStorage implementation you will ever use.
License: MIT License
The simplest angular localStorage implementation you will ever use.
License: MIT License
http://plnkr.co/edit/Y1mrNVRkInCItqvZXtto?p=preview
console:
POST http://run.plnkr.co/E1AltyBNNZWYRWaL/ 400 (Bad Request)
POST http://run.plnkr.co/E1AltyBNNZWYRWaL/ 400 (Bad Request)
if localstorage bound object is used in ngRepeat, then the object will be persisted to localstorage with $$hashkey, potentially causing the aforementioned error. this can either be addressed by using track by in the ngRepeat construct or adjusting the code in angularlocalstorage to strip the hashkey before set.
recommended change:
var saver = $window.JSON.stringify(value, function(key, val) {
if(key == '$$hashKey') {
return undefined;
}
return val;
});
angular is now 1.2.rc2, as well as angular-cookies, can you upgrade to the new version and push a new build to bower?
It will be very useful to have it as bower package!
Fix: change "var saver = $window.json.." to:
var saver = $window.JSON.stringify(value, function (key, val) {
if (key == '$$hashKey') {
return undefined;
}
return val;
});
Hi!
I was curious if you might consider unregistering the bower package called "ngStorage"?
It currently installs this package. But your readme indicates you have a new name for this package with a new bower name as well?
Hey,
This is not really an issue,
Just wanted to let you know, I implemented a wrapper service, you can check it out here:
http://ajsblackbelt.wordpress.com/2014/05/27/local-storage-cache-service/
Hi
First, I'm using your lib for a while now and it's very helpfull ;)
There is still one thing I think is missing : the possibility to clear the localStorage in one shot. It's doable with .clear() function in W3C localStorage.
Do you think it's possible to add this to your lib ?
Thanks ;)
I think new version of bower has renamed components to bower_components, thus your example code is broken on my box (unless I forked your src repo).
I personally think it makes more sense of NOT checking in "components" folder as src so you won't run into dependencies management hell.
I think this folder should be removed. The examples could reference a public angularjs cdn, or the dependencies could be fetch using bower for the example.
Reason for removing: it wastes space and increases maintenance.
app.controller('CreateCtrl', function ($scope) {
$scope.create = {a:1, b:2, c:3};
$scope.send = function () {
$scope.$emit('send', angular.copy($scope.create));
}
});
app.controller('ListCtrl', function ($scope, $rootScope) {
$scope.list = [];
$rootScope.$on('send', function (e, data) {
$scope.list.push(data);
});
}) ;
last element in
Why does this cool repo not have a CDN?
Could you ask at https://cdnjs.com/ for one?
Cannot use bower: bower install angular-localStorage
causes error:
bower not-cached git://github.com/grevory/angular-local-storage.git#~0.1.1
bower resolve git://github.com/grevory/angular-local-storage.git#~0.1.1
bower ENORESTARGET No tag found that was able to satisfy ~0.1.1
Additional error details:
No versions found in git://github.com/grevory/angular-local-storage.git
The example at http://plnkr.co/edit/Y1mrNVRkInCItqvZXtto?p=preview works but it seems to be using an older file (storage & angularLocalStorage vs $store & localStorage, etc).
Please release officially 0.3.0, to denote the change in the bower.json file.
the get method implementation in (!support) if branch is using jquery cookie when perhaps it should be using angular cookieStore.
recommend change
return privateMethods.parseValue($.cookie(key));
to
return privateMethods.parseValue($cookieStore.get(key));
When I try to use localStorage on Safari while private browsing I get an error that I cannot catch.
Cookie 'config' possibly not set or overflowed because it was too large (1018591 > 4096 bytes)!
Looks like the fallback to the $cookieStore isn't throwing an error I can catch and swallow. If I can't store it, then I don't want my app to crash.
I noticed this module uses $service, it is angular's tradition to preserve $ for its own modules, is it possible to rename it something like localStorage or storage?
Can't get this excellent tool to work for me when binding objects from cache to selectbox. When hitting F5 the value of the select is lost, the correct value is there but the select wont initiate correct.
Example:
http://plnkr.co/edit/dpdANDKAq8eeHPMj5CbG?p=preview
Any ideas?
Regards Andreas
storage.bind()
doesn't work inside a factory, I assume because there is no scope.
Passing an object doesn't work either:
app.factory('someFactory', function(storage) {
var settings = {
foo: 'bar',
lorem: 'ipsum'
}
storage.bind(settings,'foo');
});
This produces the error undefined is not a function at Object.publicMethods.bind
Hi, thanks to your library pretty useful actually !
A thing that I don't really understand in bind function it's this statement :
def = def || '';
when you define a defaut value like 0, null, or false it is transformed into an empty string in localStorage.
https://docs.angularjs.org/api/ngCookies/service/$cookieStore
Note: The $cookieStore service is deprecated. Please use the $cookies service instead.
For now, I will use $cookieStore, too (requirement from my agent).
Please update the lib in the next version, thank you :)
If you store the value false, the module will detect it as being not set:
// If a value doesn't already exist store it as is
if (!publicMethods.get(storeName)) {
publicMethods.set(storeName, opts.defaultValue);
}
I propose the following fix:
// If a value doesn't already exist store it as is
if (publicMethods.get(storeName) === null) {
publicMethods.set(storeName, opts.defaultValue);
}
@agrublev bump new version, please!
Great tool, but I can't get the binding to work.
I have several controllers and services and I'm using the angularLocalStorage to maintain state in SPA using angular ui-router.
The controller binds to a local store key. When a service sets the value in the local storage the bound value in the controller is not updated. They are updated on a hard refresh. I expected the bound values to update in the controller when the angularLocalStorage set function was called.
Added
"Angular-localStorage": "latest"
to my bower.json file.
It install fine into 'bower-components/Angular-localStorage'
However, the error is:
Error: [$injector:modulerr] Failed to instantiate module app due to:
[$injector:modulerr] Failed to instantiate module localStorage due to:
[$injector:nomod] Module 'localStorage' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
I've included the module correctly, as I've used the src file directly and is now trying to switch over to bower.
I'm not sure what I'm doing wrong but the localStorageModule.js doesn't look the same to the file in the src directoy.
Any help appreciated, thanks
Hello, would be nice if the module can $broadcast
/ $emit
events based on changes to localStorage
, or capture storageEvent
on window
. This is for notification purposes, without needing a separate $watch
somewhere else. Thanks.
I've got angular 1.3.15 and I can't install your script:/
I am using storage in my controller as
storage.bind(this, 'counter', {defaultValue: 5});
I am getting below error in the browser console when running my angular app.
TypeError: $scope.$eval is not a function
at Object.bind (http://localhost:3000/seller/bower_components/angularLocalStorage/dist/angularLocalStorage.min.js:1:1802)
at new (
Hi,
I was looking in Nuget but I can't find this package, under what name is it posted?
Thanks!
For the public get(), set() and remove() methods, if supported == false and any type of exception occurs, the code specific to localStorage will attempt to run, even though supported == false.
For example, this is the current set():
set: function (key, value) {
if (!supported) {
try {
$cookieStore.put(key, value);
return value;
} catch(e) {
$log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
}
}
// THE FOLLOWING LINES RUN WHEN THE CATCH(E) ABOVE IS TRIGGERED
var saver = angular.toJson(value);
storage.setItem(key, saver);
return privateMethods.parseValue(saver);
},
Suggest doing the following:
set: function (key, value) {
if (!supported) {
try {
$cookieStore.put(key, value);
return value;
} catch(e) {
$log.log('Local Storage not supported, make sure you have angular-cookies enabled.');
}
}
else { // THIS CODE WILL NOW ONLY EVER EXECUTE IF (supported)
var saver = angular.toJson(value);
storage.setItem(key, saver);
return privateMethods.parseValue(saver);
}
},
I was looking to update an existing app to use local storage.
This app is written consistently with "Controller as namespace" in the views and no use of $scope in the controllers themselves.
So - e.g. given that a controller exposes
this.dataObject = {}
Is there a good approach to binding that two-way into localstorage without having to re-write everything back to $scope injection on the controller?
the factory works as expected, but when I use the grunt --save, the vendor.js file that is created with all the vendors library raise an error.
Any idea?
In case you are not downloading https://github.com/ivpusic/angular-cookie (for example via bower) loading storage throws an error from angular.
Hence, add it as dependency (I downloaded this repo via bower).
Maybe the localStorage service should instead of using JSON.parse and JSON.stringify, should use angular.fromJson and angular.toJSON to prevent the dreaded "Duplicates in a repeater are not allowed" error. A blog post that describes what was happening to me with more information is at http://mutablethought.com/2013/04/25/angular-js-ng-repeat-no-longer-allowing-duplicates/
i have a a question ,when my app is working offline ,when offline i fill out few changes
,how do i sink this data when the user is online ..
can i use $scope.viewType = 'ANYTHING';
will this serve my purpose or shud i explicit write a function to write into a variable and pushing to local storage and then getting the data and updating the my LS..
Could you please update the bower name to "Angular-localStorage"? I can see the name "angular-localStorage" in README and bower.json, Thanks for sharing such good library.
Nice library! :)
Two suggestions:
bower install angular-localStorage
results in:
bower cloning git://github.com:agrublev/Angular-localStorage.git
bower caching git://github.com:agrublev/Angular-localStorage.git
bower error status code of git: 128
There were errors, here's a summary of them:
- angular-localStorage status code of git: 128
fatal: Unable to look up github.com (port agrublev) (nodename nor servname provided, or not known)
somehow the slash before your username became a colon.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.