Hello All,
I am trying to get the value from i18n resource properties but when in controller code I am executing the below-mentioned line of code , I am getting "App.controller.js:10 Uncaught TypeError: this.getView is not a function" . Please find different code section.
App.controller.js :
sap.ui.define([
"sap/ui/core/mvc/Controller","sap/m/MessageToast"
], function(Controller,MessageToast) {
"use strict";
return Controller.extend("MyApp.controller.App", {
onShow: function(){
// read msg from i18n model
var oBundle = this.getView().getModel("i18n").getResourceBundle();
var sRecipient = this.getView().getModel("helloPanel").getProperty("/recipient/name");
var sMsg = oBundle.getText("helloMsg", [sRecipient]);
// show message
MessageToast.show(sMsg);
}
});
});
App.view.js :
sap.ui.jsview("MyApp.view.App", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf controller.App
*/
getControllerName: function() {
return "MyApp.controller.App";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf controller.App
*/
createContent: function(oController) {
var oBtn = new sap.m.Button("btn1ID", {
text: "Show",
press: oController.onShow
});
var oIp = new sap.m.Input({
value: "{helloPanel>/recipient/name}",
description: "Hello {helloPanel>/recipient/name}",
valueLiveUpdate:true,
width:"20%"
});
manifest.json:
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "MyApp",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"sourceTemplate": {
"id": "ui5template.basicSAPUI5ApplicationProject",
"version": "1.32.0"
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": [
"sap_hcb",
"sap_bluecrystal"
]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView": {
"viewName": "MyApp.view.App",
"type": "JS"
},
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "MyApp.i18n.i18n"
}
},
"helloPanel": {
"type": "sap.ui.model.json.JSONModel",
"uri": "model/HelloPanel.json"
}
},
"resources": {
"css": [{
"uri": "css/style.css"
}]
}
}
}
Component.js :
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"MyApp/model/models"
], function(UIComponent, Device, models) {
"use strict";
return UIComponent.extend("MyApp.Component", {
metadata: {
manifest: "json"
},
/**
* The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
* @public
* @override
*/
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// set the device model
this.setModel(models.createDeviceModel(), "device");
}
});
});