Tina Chen
Tina Chen

Reputation: 2030

sap.ui.core.Fragment.load returns undefined

There are two FLP tiles in my app. One can access to sap.ui.core.Fragment.load, but the other cannot.

enter image description here

enter image description here

and byId returns a lazy stub ? enter image description here

They both load UI5 by

<script
  id="sap-ui-bootstrap"
  src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
  data-sap-ui-theme="sap_belize_plus"
  data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration"
  data-sap-ui-preload="async"
  data-sap-ui-compatVersion="edge"
  data-sap-ui-frameOptions='allow'
  data-sap-ui-resourceroots='{
    "monitor": "./",
    "common": "./../../../common"
  }'>
</script>

The not working one does not have Fragment.js in the SAPUI5 resource, but I can access to Fragment-dbg.js

enter image description here

I have also compared manifest.json, there is no difference. Is there any other clue?

Upvotes: 3

Views: 5662

Answers (1)

Tina Chen
Tina Chen

Reputation: 2030

I found that after sap.ui.xmlfragment(), Fragment.load() exists. So add it to sap.ui.define or .require, then it works.

sap.ui.require([
  "sap/ui/core/Fragment"
], function(Fragment){
  Fragment.load({
    name: "namespace.myFragment",
    controller: this
  }).then(function(oFragment) {
    // ...
  }.bind(this));
}.bind(this));

Thanks to @Boghyon Hoffmann:

the factory functions inside the sap.ui.* namespace have also been refactored. UI5 now provide fully asynchronous APIs on top. The old APIs are of course still available for compatibility reasons, but are also deprecated. Modularization of the SAPUI5 Core

New API must use modular way, which means use sap.ui.require / sap.ui.define.


Documentation: Legacy Factories Replacement

Upvotes: 6

Related Questions