angularjs - How to save object array to localStorage using angular local storage -
i have object of array in controller, how save object local storage , access local storage throughout app in angular (im using ngstorage)
$scope.drivers = [{ "entity$": "-/sys/daily_journeys", "name": "tom david", "journey_count": 90, "traveled_distance": "773", "total_risk": 0.367, "days": 22, "id_device": "4564645", "avg_risk": "0.0", "risk_category": "green" }, { "name": "james doc", "journey_count": "-", "traveled_distance": "-", "total_risk": "-", "days": "-", "id_device": 32423435, "avg_risk": "-", "risk_category": "none" }, {
you can use $cookiestore. set $scope (key, value) pairs. inject sharedataservice in controller.
app.service('sharedataservice', ['$cookiestore', function ($cookiestore) { var _setappdata = function (key, data) { //appid, appname) { //var appdata = { 'appid': appid, 'appname': appname }; $cookiestore.put(key, data); }; var _getappdata = function (key) { var appdata = $cookiestore.get(key); return appdata; }; return { setappdata: _setappdata, getappdata: _getappdata }; }]);
put service in main module app.
Comments
Post a Comment