$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: false, vro: false, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content
0

Writing UI5 controller functions using javasrcipt keyword prototype

Mar 28, 2017 at 11:09 AM

54

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jun Wu Mar 28, 2017 at 12:35 PM
0
jQuery.sap.declare({
	modName :"ABC.controller.View1Controller",type:"controller"});

how about this?

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0
 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?

0