Skip to Content

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

How to access Model created in Component to another Controller

Hi All,

Need help to know how can I access my Model which is created in Component.js(Fiori) and assigned to view from a view controller, below is my code

Component.js

jQuery.sap.declare("com.fiori.Component");

sap.ui.core.UIComponent.extend("com.fiori.Component",{

  createContent : function(){

  var Oview = sap.ui.view({

  id : "app",

  viewName : "com.fiori.view.App",

  type : "JS",

  viewData : { component : this }

  } );

   var oDataModal = new sap.ui.model.odata.ODataModel("http://server:8000/sap/opu/odata/sap/USERS/",true,"abcd","id1001");

  Oview.setModel(oDataModal);

  return Oview;

  }

});

I want to access above created Model(oDataModal) in different other view controllers for my CRUD operations.

Thanks

Rajesh

Former Member
replied

Hi Rajesh,

In your component.js after creating the model use -

sap.ui.getCore().setModel(oDataModel, "modelname");

so that the instance of the Model is available at the core and the retrieved using sap.ui.getCore().getModel(oDataModel) where ever required.

Hope this helps

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