I want to pass data between two controllers (in addition to routing parameters) and I would like to know the correct way to do this.
For example: when I navigate to pattern /order/{id}
, I do this in the view controller:
this.getRouter().navTo("order", {
id: sOrderId
});
I want to pass additional JSON object which I don't want to be part of routing parameter.
What should I do in this case?
--edit
Wanted to add what I like to achieve with this
I want pass data from master to detail. Both master and detail page has individual routing patterns assigned. So user can land on master or detail directly. When they land on master - user can choose bunch of detail items, and navigate to first detail item, and from there navigate to other items he/she selected earlier on master. So what I want to pass is this selection from master controller to detail controller.
Using Client-side Model
Usually, data are stored separately in models instead of assigned to local variables and passing them around. Model data can be then shared with anything that can access the model (e.g. View for data binding). Here is an example with a client-side JSONModel:
Create a client-side JSONModel which is set on a parent ManagedObject. E.g. on Component via manifest.json:
In controller A, set the object to pass before navigating:
In controller B, do something with the passed data. E.g. on
patternMatched
handler:Using NavContainer(Child) Events
There are several navigation-related events such as
navigate
,BeforeHide
,BeforeShow
, etc. which contain both views - the source view (from
) and the target view (to
).You can make use of the API
data
to pass the data. Here is an example:In controller A
In controller B
You can create a local model (usually a JSONModel) and set it to inside your app Component.
Inside each controller you can use