在工厂使用本地存储来制作CRUD角度

时间:2017-05-14 16:59:50

标签: angularjs

你好我试着学习如何使用本地存储来创建,更新,删除模块。 目前我将数据放在工厂

factory.js

angular
    .module('app')
    .factory('Experiences',function(){
    return {
       get: function() {
        return [
            {"id":1,"name": "Implementasi ProMISC","alamat": "Jakarta","bidang": "JASA KONSULTASI NON-KONSTRUKSI","mulaiKerjasama":"03/09/2017","nilaiKontrak":"1000000000","curency":"USD","buktiKerjasama":["note.txt"]},
            {"id":2,"name": "adsdsdsv","alamat": "Jakarta","bidang": "dsudmwisahi","mulaiKerjasama":"04/05/2017","nilaiKontrak":"120503","curency":"IDR","buktiKerjasama":["img.txt"]}
        ];
       }
    };
});

体验Ctrl

angular
    .module('app')
    .controller('ExperienceCtrl',['$scope','Experiences',function($scope,Experiences){
        $scope.title="List Experience";
        $scope.experiences=Experiences.get();

        $scope.deleteItem =function(experience){
            var index = $scope.experiences.indexOf(experience);
            alert("Deleting DATA: "+ index);
            $scope.experiences.splice(index,1);
        };
}]);

如何在工厂进行本地存储? 如果我使用本地工厂,我可以永久更改json(让我说删除它的一个数据)?

thankn you

0 个答案:

没有答案