Show TOC

Programmatically Instantiating HTML FragmentsLocate this document in the navigation structure

For each fragment type, SAPUI5 provides a method that can be used to programmatically instantiate a fragment.

Context

To give an example of a programmatic instantiation of a HTML fragment, you first have to define one. The following code presents an example definition:

<div data-sap-ui-type="sap.m.Button" data-press="doSomething" data-text="Hello World"></div>

This fragment can be instantiated from a controller as follows:

var myButton = sap.ui.htmlfragment("my.useful.UiPartZ", oController); // this specific fragment again needs a controller 

This instantiation can be done at any place in the code, given that a controller is available and the returned button can be used like any button.

Procedure