cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 , Problem in Calling Sub Functions to Load objects.

0 Kudos

Hi,

While going through open SAPUI5, course, week 1, tried following code.

The above code for loading image works fine.

<script>
    var oCore = sap.ui.getCore();
    var oImage3;
    oCore.attachInit(function() {
        alert("Test");
        oImage3 = new sap.m.Image({
            src: "https://sapui5.hana.ondemand.com/resources/sap/ui/documentation/sdk/images/logo_ui5.png"
        }).placeAt("content");
        oImage3.setHeight("100px");
    });
</script> 

....

Now created another function fnPlaceImage() and called via attachInit(),

the Image does not load.

The alert works fine, but image is not loaded, not placed.

Is there any restriction in calling custom functions and loading objects.

Or Is there any constraints in calling functions.

<script>
var oCore = sap.ui.getCore();
var oImage3;
oCore.attachInit(fnPlaceImage());
function fnPlaceImage() {
    alert("Test");
    oImage3 = new sap.m.Image({
        src: "https://sapui5.hana.ondemand.com/resources/sap/ui/documentation/sdk/images/logo_ui5.png"
    }).placeAt("content");
    oImage3.setHeight("100px");
}
</script>

Accepted Solutions (0)

Answers (1)

Answers (1)

ChrisSolomon
Active Contributor
0 Kudos

In a nutshell...simple answer.....it is because "attachInit" expects an anonymous callback function in there....not a named function. However, just for grins, you can do this...

oCore.attachInit(fnPlaceImage);



....and you should see your image. 😃

Thanks Christopher, it worked fine..