Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Error while using component.js

Hi,

I am trying to use component .During that i am facing an error in component.js file .Please help me to find the error.And suggest me to know more about component.js for a fresher in UI5

Please go through the code :

Error i am facing :

UIComponent.js:6 Uncaught TypeError: undefined is not a function

Index.html

---------------

<!DOCTYPE HTML>

<html>

  <head>

  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

  <script src="resources/sap-ui-core.js"

  id="sap-ui-bootstrap"

  data-sap-ui-libs="sap.m"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-resourceroots='{

  "sap.ui.demo.myApp": "./"

  }'>

  </script>

  <!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

  <script>

  new sap.ui.core.ComponentContainer({

  name : "sap.ui.demo.myApp"

  }).placeAt("content");

  </script>

  </head>

  <body class="sapUiBody" role="application">

  <div id="content"></div>

  </body>

</html>

component.js

--------------------

jQuery.sap.declare("sap.ui.demo.myApp.Component");

sap.ui.core.UIComponent.extend("sap.ui.demo.myApp.Component",{

  createContent : function()

  {

  /*var oview = sap.ui.view({

  id : "app",

  viewName : "sap.ui.demo.myApp.view.App",

  type : "JS",

  viewData : { component : this }

  });*/

  var oView = sap.ui.view({

  id : "app",

  viewName : "sap.ui.demo.myApp.view.App",

  type : "JS",

  //viewData : { component : this }

  });

  //var omodel = new sap.ui.model.json.JSONModel("model\mock.json");

  //oView.setModel(omodel);

  return (oView);

  }

});

App.view

-------------

sap.ui.jsview("view.App", {

  getControllerName : function() {

  return "view.App";

  },

  createContent : function(oController) {

  var btn = new sap.m.Button({

  text : "Hii"

  });

  return btn;

  }

});

Tags:
Former Member
Former Member replied

Hello Jagadeesh,

Two things,

1. In the App.view.js, change the first line from:

"sap.ui.jsview("view.App", {"

to:

"sap.ui.jsview("sap.ui.demo.myApp.view.App", {"

2. Create an App.controller.js with content such as:

sap.ui.core.mvc.Controller.extend("sap.ui.demo.myApp.view.App", {

});

If the above changes resolve your error, you can then add a function to the controller which handles the button's press event.

Regards,

Scott

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question