0
Good morning, I am developing an app with Ionic 3 and I have the following situation :
I am recording a list of products in the Store, after that, I need to bring the recorded data, for a list of products, IE, each item of the vector, creates a column in the list. Code:
Save to Localstorage:
localStorage.setItem("vetor", JSON.stringify(this.vetCarrinho));
Recovers from the Localstorage:
ionViewDidLoad() {
if (this.pedido.key) {
let prod: any = localStorage.getItem('vetor').split(",");
if (prod != null) {
prod = JSON.parse(prod);
if (this.vetCarrinho.indexOf(prod) === -1) {
this.vetCarrinho.push(this.pedido.produto);
}
}
}
Html :
<ion-list>
<ion-item *ngFor="let element of vetCarrinho">
{{element}}
<button ion-button color="danger" (click)="deleteProduto(element)" item-end>
<ion-icon name="trash"></ion-icon>
</button>
</ion-item>
</ion-list>
From that, he plays ALL elements in ONLY ONE COLUMN :
How do I make it create a column each element ?
How’s your
vetCarrinho
?– Marconi
[cellular,]
– user125721
in my view your code is correct, there is some detail that is not rendering correctly.
– Marconi
I tried to use split, to separate by comma, but I was not successful. I edited the question
– user125721
Try it like this to see:
let prod: any = JSON.parse(localStorage.getItem('vetor'));
 if (prod != null) {
 for(let i=0; i<prod.length; i++) {
 if (this.vetCarrinho.indexOf(prod[i]) === -1) {
 this.vetCarrinho.push(this.pedido.produto);
 }
}

 }
– Marconi
Dude, before you send to firebase, I’m going through: this.pedido.product = this.vetCart, will that be the problem ?
– user125721