0

I want to make a form (in angularJS) that when submitted is saved locally and can be accessed later. What code do I need to both read and write from this JSON file, or where can I learn how to do this?

4

2 回答 2

1

我喜欢grevory的本地存储服务:https ://github.com/grevory/angular-local-storage

您还可以查看 HTML5 Web SQL:http : //www.tutorialspoint.com/html5/html5_web_sql.htm 不过不确定它是否支持。

至于字符串处理部分,Angular 有:http ://docs.angularjs.org/api/angular.toJson和http://docs.angularjs.org/api/angular.fromJson

于 2013-08-13T02:50:07.840 回答
0

这是我在我的角度服务中的一些代码。希望你能适应你的目的

app.factory('userService', ['$rootScope', function ($rootScope) {

    var service = {

        model: {
            name: '',
            email: ''
        },

        SaveState: function () {
            sessionStorage.userService = angular.toJson(service.model);
        },

        RestoreState: function () {
            service.model = angular.fromJson(sessionStorage.userService);
        }
    }

    return service;
}]);
于 2013-08-13T06:37:07.393 回答