Quantcast
Channel: angular - local storage not working - Stack Overflow
Viewing all articles
Browse latest Browse all 7

angular - local storage not working

$
0
0

I am trying to store data in local storage when the app loads using the AngularJS ngStorage module.

I have the following code:

app.js:

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives', 'ngCordova', 'ngStorage']).run(function($ionicPlatform) {  $ionicPlatform.ready(function() {    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard    // for form inputs)    if(window.cordova && window.cordova.plugins.Keyboard) {      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);    }    if(window.StatusBar) {      // org.apache.cordova.statusbar required      StatusBar.styleDefault();    }    $localStorage.message = "Hello World";  });})

Then using my controller, I want to do the following.

controller.js:

$scope.data = $localStorage.message;

and finally output the saved message.

message.html

<div><p> Saved Message:{{ data}} </p></div>

When I check the local storage using Chrome Inspect tool, I dont see the stored message. Any idea how to save data from app.js at startup?


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>