[英]Ionic storage not assignable number to string
I want to set in ionic storage all numbers like from function below getWarrentsNumber(), but i've got an error. 我想在离子存储中设置所有数字,例如getWarrentsNumber()下面的函数中的所有数字,但是出现错误。
Error: Argument of type "number" is not assignable to type 'string. 错误:“数字”类型的参数无法分配给“字符串”类型。
this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');
this.storage.get('name').then((name) => {
console.log('Me: Hey, ' + name + '! You have a very nice name.');
console.log('You: Thanks! I got it for my birthday.');
});
},
error => {
}
);
This is a function to catch number of tasks from db: 这是一个从数据库捕获大量任务的功能:
getWarrentsNumber() {
let id = localStorage.getItem('userId');
this.peopleProvider.getAllWorkerAssignedWarrents(id).toPromise()
.then(result => {
this.NumberOfAssignedWarrents = result.length;
localStorage.setItem('DodNalog', result);
});
this.peopleProvider.getAllWorkerFinishedWarrents(id).toPromise()
.then(result => {
this.NumberOfFinishedWarrents = result.length;
localStorage.setItem('ZavNalog', result);
});
this.peopleProvider.getAllWorkerUnfinishedWarrents(id).toPromise()
.then(result => {
this.NumberOfUnfinishedWarrents = result.length;
localStorage.setItem('NezavNalog', result);
console.log(result);
});
}
This line throws the error, because you are setting the key
as a number. 此行引发错误,因为您将
key
设置为数字。 As per ionic docs, the first parameter ( key
) should be a string. 根据ionic docs,第一个参数(
key
)应为字符串。
this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');
This should be changed as 这应该更改为
this.storage.set('LOCAL STORAGE BROJ',this.NumberOfAssignedWarrents);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.