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

how to access class inside controller


I am new to SAPUI5 and trying something using classes . i have created a class using model/person.js in side my project structure which has constructor to take first name and last name and returns a JSON model wrapping that data .

I am trying to use this in my controller but i don't see a way to access this properly inside the controller .

Controller initialized like below and inside onInit method i am trying to call sap.ui.require to initialize the class which is defined .

sap.ui.controller("com.test.objects.view.mainView", {

onInit: function() {

sap.ui.require(['com/test/objects/model/Person'], function(Person) {

this.p = new Person({firstname:"Testing",lastname:"Name"});





please help me how can i access the class defined in other JS file and call the methods and populate the data into VIew .


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jan 12, 2016 at 07:54 PM

    so what is not working ?

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Maksim Rashchynski

      i have below error on the console .

      Uncaught TypeError: sap.ui.require is not a function

      how i can use "" if above not ther e. when i try below i am getting syntax errors on SAP Web IDE."com.test.objects.model.Person");

      var p = new Person({firstname:"Testing",lastname:"Testing"});

      [i tried new com.test.objects.model.Person ({firstname:"Testing",lastname:"Testing"});]




  • Posted on Jan 12, 2016 at 08:00 PM

    If you declared"com.test.objects.model.Person");

    com.test.objects.model.Person = {

    firstname: "",

    lastname: "'


    then you could do

    sap.ui.require(['com/test/objects/model/Person'], function(Person) {

    Person.firstname = "Testing";

    Person.lastname = "Name";




    SAP - Technology RIG

    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.