hello everyone,
I am trying to fetch all the values which I have stored in my local-storage,and the output should be like this:
But I am getting the output like this:
I have created the form in which I am entering the values and want to fetch all the names of the account here,but clicking on the account I am getting the result like this.
this is my AddaccountProvider.ts code:
export class AddaccountProvider {
constructor(public http: Http,private storage:Storage) { //
console.log('Hello AddaccountProvider Provider');
}
set(key, account)
{
this.storage.set(key, account);
}
get(key)
{
return this.storage.get(key);
}
isAccountPresent()
{
return new Promise((resolve, reject) => {
this.storage.forEach( (value, key, index) => {
resolve(true)
});
});
}
getAccountList(){
return new Promise((resolve, reject) => {
let accounts = [];
this.storage.forEach( (value, key, index) => {
// value = JSON.parse(value);
accounts.push(key);
}); setTimeout(() =>{
if(accounts && accounts.length > 0){
// console.log(accounts);
resolve(accounts);
}
},
1000);
});
}
getAllAccounts(){
return new Promise((resolve, reject) => {
let accounts = [];
this.storage.forEach( (value, key, index) => {
value = JSON.parse(value);
accounts.push({name: key, created: new Date(value.created).toLocaleDateString() ,
budget: value.budget, obalance: value.balance });
});
setTimeout(() =>{
if(accounts && accounts.length > 0){
// console.log(accounts);
resolve(accounts); }
},
1000);
});
}
this is the function of loading the account:
logEntry(){
if(!this.accountSelected)
{
alert(“Please select an account first”);
return;
}
this.store.get(this.accountSelected).then(data =>
{ this.register = JSON.parse(data) || ;
if(!this.entry.deposit || this.entry.deposit == '') this.entry.deposit = 0;
if(!this.entry.withdraw || this.entry.withdraw == ‘’) this.entry.withdraw = 0;
let balance = this.entry.deposit - this.entry.withdraw;
console.log("Add “+this.register.checkbook[this.register.checkbook.length-1].balance+” & "+balance);
balance = parseInt(balance.toString()) + parseInt(this.register.checkbook[this.register.checkbook.length-1].balance);
let entryData = { date: this.entry.date, num: this.entry.num, description: this.entry.description,
r: this.entry.r, withdraw:
this.entry.withdraw,
deposit: this.entry.deposit, balance: balance
};
this.register.checkbook.push(entryData);
console.log(JSON.stringify(this.register));
this.store.set(this.accountSelected, JSON.stringify(this.register));
});
} loadCheckbook(account)
{ this.store.get(account).then(data =>
{ this.register = JSON.parse(data) ||
; console.log(“Updating…”);
});
}
updateSelectedAccount(account)
{
this.accountSelected = account;
this.loadCheckbook(account);
}
Thanks in advance