cancel
Showing results for 
Search instead for 
Did you mean: 

Get Access to Controller from JS View

Former Member
0 Kudos

Hi all

How to get access to the view controller from the js view?

I tried the followings, but didn't work

this.getControllerName()   

sap.ui.getCore().byId(<viewname>).getController()

What is the correct way to get the controller.

Regards

Aakash

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Aakash,

1. If u want to access the controller of the same view then you can use,

           oController.method_name();

2. If you want to access the controller of one view in another view then you can use,

          sap.ui.controller("project_name.view_name").method_name();

Thanks

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

In same view, You get bydefault "oController". oController return current controller of this view,If you want to access controller method use oController.method_Name()

Thanks

Manoj

former_member182294
Active Contributor
0 Kudos

The JS view provides a hook method called createContent : function(oController) the parameter oController is the instance of controller and you can access all the methods of controller.

Thanks

Abhilash

Former Member
0 Kudos

Hi Abhilash

If I have to get a reference to the controller outside of createContent, how can I get.

Thanks

Sandip

former_member182294
Active Contributor
0 Kudos

Hi,

You can create a global variable and assign the reference to it from createContent method.

Or as the view initialization starts from createConent method, whatever the additional methods you are writing they should be called from createContent method only, so you can pass oController reference from there only. Let us know your requirement so that we can suggest alternate approach.

Thanks

Abhilash