multiple executions of page constructor using navP

2019-09-17 14:58发布

问题:

I need to search customers and items from add-invoice page.For that I have created two separate pages call customer-search and item-search.When I search the customer I have to go to the customer-search page and come back to the add-invoice page with customer detail.After that in the same same way I have to go to the item-search page multiple times for get multiple items and come back to the add-invoice page with items details.

To do that task,I'm passing navParams from the two pages to add-invoice page.

set navParams in customer-search page

itemTapped($event, customer) {
  this.navCtrl.push(AddInvoicesPage, { customerData: customer });
}

set navParams in item-search page

itemTapped($event, item) {
  this.navCtrl.push(AddInvoicesPage, { itemData: item });
}

access to the navParams in add-invoice page

this.customer = this.navParams.get('customerData');
this.item = this.navParams.get('itemData');

When I'm accessing the data separately It works.But the problem is, when I'm accessing the itemData after accessing the customerData, customerData will become "undefined".In the same way itemData will become undefined, when I'm accessing customerData after accessing itemData.

I just need to access to both customerData,itemData in the same time.What is the most suitable way to overcome this problem! Give me the best suggestion.Thank you!