Issue
I have a modal with a select to filter regions. When I open the modal, I select the region and show the data for that region, so I want to send that data back to the First Page. And I think I did it right, because on the CONSOLE I see the filtered data, but I do not know how to display then in my HTML on the First Page. Can anyone help me with this? I do not know what exactly I need to do.
MODAL.TS
export class FiltrosModalPage implements OnInit {
public selectedFilter: string = 'regiao.id';
regiao: any;
regioes: Regiao[];
myParam: string;
produtos: Produto[];
produtossubcategoria: Produtosubcategoria[];
constructor(
private viewController: ViewController,
public navCtrl: NavController,
public db: DatabaseProvider,
public navParams: NavParams,
public viewCtrl: ViewController
) {
console.log(navParams.get('val'));
this.regioes = navParams.get('val');
}
selecionaregiao(id) {
this.db.getProdutosregiao(id)
.then(data => this.produtos = data)
.catch(error => console.log('Something want wrong!'));
console.log('passou em tudo')
}
dismiss() {
let data = this.produtos;
this.viewCtrl.dismiss(data);
}
}
HOME.TS
openFiltrosModal() {
this.openModal('FiltrosModalPage');
}
openModal(pageName) {
let filtrosModal = this.modalCtrl.create(pageName, {'val': this.regioes}, { cssClass: 'inset-modal' });
filtrosModal.onDidDismiss(data => {
console.log('MODAL DATA', data);
this.value = data;
});
filtrosModal.present();
}
As in the console image, I'm getting this data on the first page html. But I do not know how to display then.
Solution
Since you saved the data in a property of your class (this.value
) you just need an ngFor to iterate through the arrays and display the data.
You can do as this on your HTML
<!-- Here you'll use the ngIf to just show the list itens if there's something on value -->
<ion-list *ngIf="value">
<!-- ngFor'll iterate your array and render a new element for every item in your array -->
<ion-item *ngFor="let item of value">
<!-- then you can access an property of your object in that array position -->
{{item.nom_regiao}}
</ion-item>
</ion-list>
Be sure you value
doesn't have any value before filtering in the modal, if it's initialized with any value the ngIf
condition must be changed.
Answered By - Gabriel Barreto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.