Uncaught TypeError: Cannot read property 'initialize' of undefined

Currently I am working on an Upgradation project; I am facing the Below Exception when I instantiate the Custom Router Class from the Component.js; the Application specific configurations are configured in separate manifest.json file. The issue is that I couldn't able to read the manifest.json configs from Component.js.

I have created SAP Ui5 applications from Scratch in which I have implemented thru SAP's Best Methodologies and they were all working perfectly, I have even cross checked the Manifest files of a working Ui5 Application, Everything is perfect, but still I am unable to spot the issue and I am getting the below Exception.

Exception/Error:

UIComponent.js:6 Uncaught TypeError: Cannot read property 'initialize' of undefined at f.init (Component.js:21) at f.constructor (sap-ui-core.js:135) at f.constructor (sap-ui-core.js:141) at f.constructor (UIComponent.js:6) at new f (sap-ui-core.js:135) at Object.sap.ui.component (sap-ui-core.js:141) at F.a.onBeforeRendering (ComponentContainer.js:6) at F.a._callEventHandles (sap-ui-core.js:147) at F.a._handleEvent (sap-ui-core.js:147) at t (sap-ui-core.js:147)

Component.js [Please note: Below I have shared only init method ]

sap.ui.define([ "sap/ui/core/UIComponent", "xxxx/app/xxxxx/MyRouter"
], function (UIComponent , MyRouter ) { return UIComponent.extend("xxxx.app.xxxxxx.Component", { metadata: { manifest: "json" }, init : function() { debugger; // IMDK901184 UIComponent.prototype.init.apply(this, arguments); // I am getting the exception once the below line is executed. this.getRouter().initialize(); }
} });
});

manifest.json

{ "_version": "1.12.0", "sap.app": { "id": "xxxxx.app.xxxxx", "type": "application", "i18n": "i18n/messageBundle.properties", "title": "xxxx", "description": "xxxx", "applicationVersion": { "version": "1.0.0" }, "dataSources": { "mainService": { "uri": "xxxx.app.xxxxxx.AppScripts.config.baseURL", "type": "OData", "settings": { "odataVersion": "2.0" } } } }, "sap.ui": { "technology": "UI5", "deviceTypes": { "desktop": true, "tablet": true, "phone": true }, "supportedThemes": [ "sap_bluecrystal" ] }, "sap.ui5": { "rootView": { "viewName": "xxxxx.app.xxxxxx.POSView.App", "type": "XML", "async": true, "id": "idAppControl" } , "dependencies": { "minUI5Version": "1.30", "libs": { "sap.m": {} , "sap.ui.core": {}, "sap.ui.layout": {} } }, "models": { "i18n": { "type": "sap.ui.model.resource.ResourceModel", "settings": { "bundleName": "xxxx.app.xxxxxx.i18n.messageBundle" } }, "oMainModel": { "dataSource": "mainService", "settings": { "useBatch": false } } } , "routing" : { "config" : { "routerClass" : "xxxxxx.app.xxxxxx.MyRouter", "viewType" : "XML", "viewPath" : "xxxxxx.app.xxxxxx.POSView", "controlId": "idAppControl", "targetAggregation" : "detailPages", "clearTarget" : "false" } , "routes" : [ { ] } }
} 
2

2 Answers

I guess 'coz of the current installed SAP Ui5 Version is 1.26 and so the new type of declaring Manifest.json doesn't support here.

Refactored back to the Metadata section in component.js

1

I think you need to implement the getRouter() method something like :

init : function() {
..
..
}
getRouter : function () { return sap.ui.core.UIComponent.getRouterFor(this);
}
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like