Search code examples
angularonsen-ui2

How to refresh previous page after current page closes in OnSen and Angular 2+


I have a product-list page where I show list of all products. From this page there is link to open on product-new page where I add new product. After adding the product in DB I want to show newly added product in my previous product-list page after current product-new page is closed. I could not find any solution to pass newly added product back to previous page or refresh it to reload product list. Could you please help me with this.


Solution

  • nmg49 - Thank you for your help. Yes thats the way to talk between 2 components in Angular, but in OnSen I think its little different. Please correct me if I am wrong.

    Anyways I managed to achieve what i wanted. This might not be best practice or right way of doing that, but I will stick with it till I find a better solution.

    From my product-new component, I replaced it with product-list page rather than just poping it. Doing so new product-list will be created on top of the stack with fresh data. But then there will be 2 product-list in the stack back to back. Top on with refreshed data, 2nd top with old data. Now delete the 2nd top product-list from stack and your are good now.

    Below is my code.

    this.navi.nativeElement.replacePage(ProductListPageComponent,{slide:‘left’}); this.navi.nativeElement.removePage(1); // 1 represents the index of the previous ProductListPageComponent, this will be different in your case.

    Please let me know know if there is a better way of doing that.