cancel
Showing results for 
Search instead for 
Did you mean: 

Writing UI5 controller functions using javasrcipt keyword prototype

prashantsoni
Explorer
0 Kudos

When i create a simple UI5 app in webide, the default controller code generated is:

sap.ui.define([
	"sap/ui/core/mvc/Controller"
], function(Controller) {
	"use strict";


	return Controller.extend("ABC.controller.View1", {


	});
});

Now, i prefer writing functions using keyword prototype and hence wanted to change this and changed to:

jQuery.sap.declare({
	modName : "ABC.controller.View1",
	type : "controller"
});


sap.ui.controller("ABC.controller.View1", new ABC.controller.View1Controller());


ABC.controller.View1Controller = function() {
};

Here, editor gives error as ABC is not defined and on running the app, the console gives Type error: ABC.controller.View1Controller is not a constructor.

Any idea why this should be happening?

In Index.html property data-sap-ui-resourceroots='{"ABC": ""} is also declared.

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos
jQuery.sap.declare({
	modName :"ABC.controller.View1Controller",type:"controller"});

how about this?

prashantsoni
Explorer
0 Kudos

This will not work as the modName is always the module name of the object be it view or controller. Because it's literal translation is to load ABC/controller/View1.js file and register it. See the sdk - https://openui5.hana.ondemand.com/#docs/api/symbols/jQuery.sap.html#.declare

junwu
Active Contributor
0 Kudos
 new ABC.controller.View1Controller some place you have controller in the name. do u have to make it consistent?

anyway, i think it may not work. "extend " did a lot of things behind the thing. what the point of your try?