I'm loading a list of firebase
to display some items for selection via checkbox, true, or false. I'm trying to benefit from the filter
or map
command to only get the items that have propriedade selecionada == true
, but I'm not getting success, can anyone tell me how I could do it correctly? What is the best practice, or give me some example?
My html looks like this:
<ion-item>
<ion-label fixed class="label-format">Escolha os itens</ion-label>
</ion-item>
<button ion-button color="dark" class="botao-pesquisar" (click)="exibirItens()">
<ion-icon name="arrow-dropdown"></ion-icon>
</button>
<div *ngIf="botaoProdutos">
<ion-list *ngFor="let produto of produtosLista | async">
<ion-item>
<ion-label>{{produto.descricao}} {{produto.preco}}</ion-label>
<ion-checkbox [(ngModel)]="selecionado"></ion-checkbox>
<ion-input type="number" placeholder="Qtd" color="dark"></ion-input>
</ion-item>
</ion-list>
<button ion-button color="dark" (click)="filtro()">Escolher</button>
</div>
My role:
filtro(){
this.produtosSelecionados = this.produtosLista.map((_selecionado) => {
return this.selecionado == true;
});
console.log('o teste : ' + this.produtosSelecionados);
}
where: - Selected products is a variable that should store the selected == true. - list products is my list of items coming from FIREBASE is a OBSERVABLE. - selected is the property I passed inside my NGMODEL, it returns a true or false.
When I run this function, my console.log
returns only:
Test: [object Object]