cancel
Showing results for 
Search instead for 
Did you mean: 

[UI5] How to deal with duplicated ID error?

super_yan
Advisor
Advisor
0 Kudos

I have a fragment: MyFragment. Sample code is:

// MyFragment
<Label id="my_label_id" text="my label" />

My fragment is contained by other views:

MyView contains both Fragment1 and Fragment2, and Fragment1 and Fragment2 contains MyFragment.
In MyView, there are 2 MyFragment, so it contains 2 Label with same ID: "my_label_id". This leads to a duplicated ID error.
How to deal with this error?

View Entire Topic
FlorianVogt
Advisor
Advisor

How do you instantiate the fragment? In the "MyView" or in a controller?

Option 1: in the view. See https://ui5.sap.com/#/topic/234320f8d8ee45b39c60893116d60351 You have to give an "id" to the fragment to enable prefixing of the fragment content.

Option 2: in the controller. See https://ui5.sap.com/#/topic/d6af195124cf430599530668ddea7425 by using the "loadFragment" API the ID prefixing is automatically enabled