Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

UIComponent's Model can not be accessed in View-Controller

Hi,

I got the following problem:

I've done the SAPUI5 walkthrough tutorial in which in Component.js a model has been set via following code where this is sap.ui.core.UIComponent

var oInvoiceModel = new JSONModel(jQuery.sap.getModulePath(sNamespace, oConfig.invoiceLocal));

this.setModel(oInvoiceModel, "invoice");

But in view controller I have no access. I have tested some ways like:

this.getView().getModel("invoice")

sap.ui.core.UIComponent.getModel("invoice")

...

But everytime the result is undefined or empty.

I thought when something is set in Component.js it is aviable everywhere...

What I want to do in the end is setting a model in Component.js and loop over some data in this model in the controller of the view to build a dynamic UI.

Any ideas how I can accomplish this?

Thank you,

Dominik

Former Member
replied

Hi Dominik,

Try like this in your controller and check?

var oComponent = this.getOwnerComponent();          //Returns the Component

oComponent.getModel("invoice");

Regards,

Sai Vellanki.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question