Skip to Content
author's profile photo Former Member
Former Member

Uncaught TypeError: this.getView is not a function

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");

}

});

});

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jul 24, 2016 at 09:38 AM

    Hi Mayank,

    It may be the context problem. Can you try either of these:

      var oBtn = new sap.m.Button("btn1ID", {
      text: "Show",
      press: [oController.onShow, oController]
      });
    

    (or)

      var oBtn = new sap.m.Button("btn1ID", {
      text: "Show",
      press: jQuery.proxy(oController.onShow, oController)
      });
    

    Regards,

    Sai.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.