I have two controllers and one XML file. I want to call a function of the second controller from the first controller. The function is supposed to change the text of the xml file associated with the second controller.
This is how I'm calling the function of the second controller from the first:
sap.ui.controller("project.controller.one").set("pancakes");
This is the function in the second controller:
set: function (text) {
alert(text);
this.getView().byId("label0").setText(text);
}
The XML just has a Label with an id of label0.
I get the following error:
Uncaught TypeError: Cannot read property 'byId' of undefined
whenever I reach this line:
this.getView().byId("label0").setText(text)
However if I place this in the onInit of controller two:
this.getView().byId("label0").setText("bananas")
then the label will change to "bananas" with no error.
What am I missing?
console.log(this)inset, see if it looks like a controller. If it does, thengetView()probably didn't work. Then check<mvc:view controllerName="project.controller.one"in the corresponding view. - JJPandarisap.ui.getCore().byId()? - KristoffDT