Reputation: 570
So we determine what is in the sap core:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel"
], function (Controller,History,JSONModel)
My sap app id: "sap.ui.test
".
So I want to connect the controller to one that already exists:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel",
"sap/ui/test/webapp/controller/TopMenu"
], function (Controller,History,JSONModel,TopMenu)
And I get an error:
Error: failed to load 'sap/ui/test/webapp/controller/TopMenu.js
.
Although the road looks like right. Project structure attached in the screenshot.
I can not understand whether it is possible to identify the controller in such a way?
Upvotes: 0
Views: 579
Reputation: 3948
You would have to use
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel",
"sap/ui/test/controller/TopMenu.controller"
], function (Controller,History,JSONModel,TopMenu)
That's because of the old controller naming convention: Your controllers have to be named ABC.controller.js
.
The sap.ui.define
function searches for files and is not aware of this convention. It does not know that you would like to load a controller this time.
Upvotes: 1
Reputation: 433
try
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/core/routing/History",
"sap/ui/model/json/JSONModel",
"sap/ui/test/controller/TopMenu"
], function (Controller,History,JSONModel,TopMenu)
You do not need to tell your app the exact path, you did this already within you Index.html
(something like data-sap-ui-resourceroots='{"sap.ui.test": "sap/ui/test/webapp"}'>
)
Upvotes: 0