Soumya Gangamwar
Soumya Gangamwar

Reputation: 1022

difference between javascript localstorage and angular localstorage($localstorage)?

I am new to angular . Is there any specific resons to use $localstorage(ngStorage) instead of regular javascript localstorage

What is difference.

Can any one please explain me?

Upvotes: 0

Views: 285

Answers (2)

Amygdaloideum
Amygdaloideum

Reputation: 4863

ngStorage just wraps localStorage in an angular service, with a different API. One big advantage of doing this is that it is easier to mock localstorage when writing unit tests. The same reason why you use $window instead of javscript native window.

Upvotes: 0

Nikhil Mohanan
Nikhil Mohanan

Reputation: 1260

if you are using regular javascript localStorage to save an object in localStorage every time you have to stringify it, because localStorage only accepts string type data.but if you use ngStorage it will do all JSON.stringify() and JSON.parse() for you.

Upvotes: 1

Related Questions