LocalStorage Test

by robcampo

HTML

<div ng-app="custom">
<div ng-controller="LocalStorageCtrl">
    <div>{{localStorageVal}}</div>
    
    <input type="text" value="" ng-model="localStorageInput" />
</div>
</div>

JavaScript

var customModule = angular.module("custom", []);

function LocalStorageCtrl($scope) {
    $scope.$watch("localStorageInput", function(newVal, oldVal) {
        console.log("localStorageInput changed args: ", arguments);
        console.log("localStorageInput changed newVal: ", newVal);
        
        //$scope.localStorageVal = newVal;
        localStorage.setItem("testStorage", newVal);
    });
    
    $scope.localStorageVal = localStorage.getItem("testStorage");
}