Introduction
Local Storage is the awesome feature of the latest Browsers. The developer can use this feature to store some data into the Browser.
The data can be stored, using Key, value pair in the Local Storage and the value can be accessed, using Key.
The data can be stored, using Key, value pair in the Local Storage and the value can be accessed, using Key.
The syntax to store into Local Storage is given below.
- localStorage.setItem(likeKey, likeValue);
- var voting = localStorage.getItem(likeKey);
Write the code, given below into controller.
Save Likes.
Save Likes.
- controller.saveLikes = function (votingId) {
- var votingKey = votingId;
- var existingVoting = controller.getLikes(votingId);
- if (existingVoting === 'NaN' || existingVoting === null) {
- existingVoting = 0;
- }
- var vote = parseInt(existingVoting) + 1;
- localStorage.setItem(votingKey, vote);
- controller.getLikes(votingId);
- }
- controller.getLikes = function (votingId) {
- var votingKey = votingId;
- controller.getTotalLikes();
- var voting = localStorage.getItem(votingKey);
- if (voting === 'NaN' || voting === null)
- return 0;
- return voting;
- }

Humayun Kabir MamunPosted Oct 13, 2016, 4:02 AM
Nice...