Skip to content Skip to sidebar Skip to footer

Methods Assigned In Xml Fragment Not Triggered

I'd like to attach a liveChange event to the Input field of the reusable Fragment-based Dialog (Walkthrough Step 19: Reuse Dialogs). In XML-template HelloDialog.fragment.xml I've a

Solution 1:

In order to enable triggering methods (e.g. event handlers, formatters, ...) from a fragment, the controller instance (this) or a plain object should be assigned to the option controller when creating the fragment. With the API loadFragment (available since 1.93), the controller instance is added as a listener object by default.

Given this as a reference to the current controller instance:

Since UI5 1.93

this.loadFragment({ name: "my.Fragment" });

In the above API, the id and controller are this.getView().getId() and this by default respectively. And the loaded fragment is added to the <dependents> aggregation of the view automatically as well (unless addToDependents: false). No need to assign them explicitly.

The advantages of using loadFragment are also mentioned in the topic Instantiation of Fragments.


Since UI5 1.58

// Fragment required from "sap/ui/core/Fragment"Fragment.load({
  id: this.getView().getId(),
  name: "my.Fragment",
  controller: this, // or a plain object that contains the event handlers
});

UI5 1.56 and below

// Deprecated!
sap.ui.xmlfragment(this.getView().getId(), "my.Fragment", this);

Post a Comment for "Methods Assigned In Xml Fragment Not Triggered"