Reputation: 1022
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
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
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