Atlas
Atlas

Reputation: 241

Re-loading the controller after Navigation ( SAP UI 5)

I have a UI5 Application with (JS View) a few pages & navigation between them. I am using mutual oModels for transfering data ( For example I am choosing some item on 2. page and I am showing the choosen items on 3. page etc.)

My problem is after navigation the Controller will be loaded only once. And I can't update my Models which means my View won't show the latest datas that I've added to oModel .

Is there anyway for me to handle this problem ? How can I manage to reload my Controllers ( onInit lifecycle function etc. )

PS: oModel.refresh(true) on navigation function doesn't do what I need-

If you need to see my code I can add the relevant part

Upvotes: 0

Views: 3973

Answers (1)

Jorge Martins
Jorge Martins

Reputation: 321

The onInit lifecycle function is only supposed to run once. If your goal is to run some logic every time you enter one of your screens, you should implement a RoutePatternMatched event handler in your controllers.

Use sap.ui.core.UIComponent.getRouterFor(this); to get your router instance and call the function attachRoutePatternMatched to attach your event. You can look into https://openui5.hana.ondemand.com/#/api/sap.m.routing.Router for more details.

Upvotes: 2

Related Questions