I want to set in ionic storage all numbers like from function below getWarrentsNumber(), but i've got an error.
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. As per ionic docs, the first parameter ( key
) should be a string.
this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');
This should be changed as
this.storage.set('LOCAL STORAGE BROJ',this.NumberOfAssignedWarrents);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.