I've been checking last openui5 documentation and I saw that there is a "new way" of creating classes.
So now, using sap.ui.define we can create classes in a AMD way like the following -
sap.ui.define(['jquery.sap.global', 'sap/ui/base/Object'],
function(jQuery, Object) {
"use strict";
var foo = Object.extend("Foo", {
metadata : {
properties : {}
}
});
foo.prototype.someFunction = function(){};
return foo;
},true);
The thing is that I'm not sure how to call this kind of classes from controllers. I would like to use AMD syntax in the control, but I haven't found any example -
(function() {
'use strict';
sap.ui.controller('settings.mvc.controller.App', {
onInit: function() {
//Foo is always undefined
},
});
})();
I think what you are looking for is sap.ui.require():
https://github.com/SAP/openui5/blob/master/src/sap.ui.core/src/jquery.sap.global.js#L2488
(note the difference to jQuery.sap.require()!)
This function is new and not yet available in the current stable release 1.26, but as soon as the next beta preview is out (or when you build UI5 on your own), you can write something like:
sap.ui.require(['Foo'], function(Foo) {
Foo.someFunction();
});
This is the symmetric counterpart to sap.ui.define() and works asynchronously, so I guess it is what you are looking for.
(I assume your question is about loading Foo from a different file, because when written within one file, it is already defined: http://jsbin.com/lagiviyoja/1/edit?html,output)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With