I'm trying to retrieve an OData model from inside onInit function from a controller in SAPUI5 for storing a property into a local variable. I have tried the following without success:
var oModel = this.getView().getModel(); // returns undefined
var oModel = sap.ui.getCore().getModel(); // returns undefined
It it seems like the model is not yet set when the onInit is running. Because of this, I have tried:
var oModel = this.getOwnerComponent().getModel(); // returns empty odata object
var value = oModel.getProperty("/Collection/Property"); // returns undefined
The exact same code works just fine in all other functions except onInit, but I need it inside this function.
How can I retrieve the model and property in onInit?