cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

getComponent

Former Member
0 Likes
6,546

Hi,

I'm building an App using the Component approach which is great. But now I'm facing the problem that I can't access my parent (or any other) component from within a component. I came to know that there is a method getComponent on the core but


sap.ui.getCore().getComponent("myComponentId")

does not give me anything.


sap.ui.getCore().getRootComponent()

doesn't return anything either.

This is the code I use to create the component:


new sap.ui.core.ComponentContainer("componentId", {

        height : "100%",

        width : "100%",

        name : "com.component.my.nice",

        propagateModel: true

      });

The whole thing is running in a sap.m.Shell + sap.m.SplitApp. The SplitApp is created as the root component of the Shell in my index.html like this:


new sap.m.Shell("Shell", {

            app: new sap.ui.core.ComponentContainer("RootContainer", {

              height : "100%",

              width : "100%",

              name : "com.component.root",

              displayBlock : "true",

              mode : "HideMode"

            })

          }).placeAt("content");


What am I doing wrong and why can't I query my components? How can I access the general component registry?


Cheers

Christian

View Entire Topic
TheVivekGowda
Explorer
0 Likes

I use below code snippet to access root component

sap.ui.core.Component.getOwnerComponentFor(this.getView())

Using this we can access root component models & router too. I do create helper functions in child app base controller file so that I can reuse it throughout the app.

/**
* Returns root component instance
*/ 
getRootComponent: function(){
  return sap.ui.core.Component.getOwnerComponentFor(this.getView());
},