本地草料和 Angular - 从本地存储获取项目的问题

Local Forage and Angular - issue with Get Item from Local Storage

我有一个 angular model 命名行。

我有一段代码尝试使用 LocalForage 从本地存储中获取数据并将本地数据设置为行模型。

显然,当执行获取项目的本地存储回调时,$scope.rows 模型超出了范围。

有没有办法,我可以实现这个,即将本地存储的值设置为行模型?

    localforage.getItem(localBlogKey, function (err, readValue) 
    {
     if (readValue !== null && readValue !== undefined) 
         {
           var localdata = readValue.data;                    
           $scope.rows = angular.fromJson(localData);
         }
     });

由于这段代码异步运行,$scope.rows 超出范围?是否有同步方式从 localforage 中提取数据?

这是使用 ngStorage 模块实现的。 导入 ngStorage 模块,然后使用下面的密钥访问 localstorage 项目

  localstorage.myKey = "myValue";

这是同步的,因此我的问题已解决。