Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught SyntaxError: Unexpected token _ in JSON at position 0 #260

Open
eaidland opened this issue Feb 21, 2017 · 2 comments
Open

Uncaught SyntaxError: Unexpected token _ in JSON at position 0 #260

eaidland opened this issue Feb 21, 2017 · 2 comments

Comments

@eaidland
Copy link

eaidland commented Feb 21, 2017

Hi!
Got alot of error messages in console when using this module:
Uncaught SyntaxError: Unexpected token _ in JSON at position 0(…) ngStorage.js:220

event.newValue ? $storage[event.key.slice(prefixLength)] = deserializer(event.newValue) : delete $storage[event.key.slice(prefixLength)];

Changed to

event.newValue && !angular.isUndefined($storage[event.key.slice(prefixLength)]) ? $storage[event.key.slice(prefixLength)] = deserializer(event.newValue) : delete $storage[event.key.slice(prefixLength)];

Now there's no error messages :)

@kutu
Copy link

kutu commented Apr 19, 2017

i have this issue too
i use angular and iframes on one page, and all pages use local storage, and this error always happens
there is some event come from angular into ngstorage and its value starts with _

untitled

but if its just one app page with no iframes, everything is fine

@floriangosse
Copy link

I have the same problem and I think that's because some parts of the application don't store JSON serialized values in the localStorage and ngStorage tries to deserialize every value as JSON (

return providerWebStorage && deserializer(providerWebStorage.getItem(storageKeyPrefix + key));
).

I think you could try to set your own deserializer which catches these errors:

var deserializer = function (value) {
    try {
        return JSON.parse(value);
    } catch (err) {
        // We expect that the error is a JSON parsing error.
        return value;
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants