Vandervidi
Vandervidi

Reputation: 692

Binding to localStorage in ionic doesnt work

Im working on an ionic application and im having some trouble binding a scope variable to a local storage var.

*Im using the ngStorage library.

in my controller I did :

$scope.name = $localStorage.name;

in html

<div data-ng-bind="name"></div>

I also have a sevice function that is executed in app.module().run() and initiates the local storage "name" variable from an external server.

I tested the local storage and its value is ok! The problem im having is with the HTML that doesnt get updated in real time when the value of the $localStorage.name changes. What am i doing wrong?

Upvotes: 2

Views: 545

Answers (1)

Sabarish
Sabarish

Reputation: 531

For dynamic update, can you try using this method in controller

$scope. name = function(){ return $localStorage.name; }

and in your html please add the below line

<div data-ng-bind="name()"></div>

Upvotes: 3

Related Questions