this.dataObj.push不是一个函数,在尝试按本地存储密钥值推送数据时收到错误

时间:2017-09-01 06:40:16

标签: angular typescript

我正在尝试将数据推送到我的本地存储值,但是它给了我错误this.dataObj.push不是函数

  

无法找到我出错的地方,sectionObj,dataObj都是数组,请指教

file.ts

myname = '';
sectionObj = [];
getresume = {};
dataObj = [];
data = '';
save() {

    this.sectionObj = [{
        "name": this.myname,
        "contactno": "0",
        "email": "a@a.com"
    }];


    this.data = localStorage.getItem('resume'); //get existing item in localstorage
    if (this.data) //check if it exists or not empty
    {
        this.dataObj = JSON.parse(this.data); //parse string
        this.dataObj.push({
            "name": this.myname,
            "contactno": '2',
            "email": "a@a.com"
        });

    }

    localStorage.setItem("resume", JSON.stringify(this.dataObj));
}

0 个答案:

没有答案