为什么我需要在localStorageService中检测变量的刷新页面?

时间:2016-02-05 06:16:19

标签: javascript angularjs

我正在使用AngularJS和localStorageService开发一个项目(用于保存变量),我在一个页面中使用localStorgaService,用于examplo / mainApp / profile,以保存对象但是当我更改页面以读取变量时来自localStorageService时,当我验证每个我需要读取变量时,它不识别对象的属性,但是当我刷新页面时,对象被识别。我的问题如何在不刷新页面的情况下识别变量?。

我使用此库:https://github.com/grevory/angular-local-storage

更新 这是我保存变量

的工厂
(function() {
    'use strict';
    angular
        .module('app')
        .factory('Profile', Profile);
    function Profile(localStorageService) {
        var service ={
            setProfile:setProfile,
            clearProfile:clearProfile,
            profileInfo:profileInfo,
            isValidated:isValidated
        };
        function isValidated()
        {
            var user = profileInfo();
            if(user===null)
                return false;
            if(user.isValidated===0)
                return false;
            return true;
        }
        function clearProfile()
        {
            return localStorageService.remove('profile');
        }
        function profileInfo()
        {
            return localStorageService.get('profile') || null;
        }
        function setProfile(profile)
        {
            localStorageService.set('profile', profile);
        }
        return service;
    }
})();

0 个答案:

没有答案