I want to change label for tab dynamically, but that's not working.
Please find the related code below:
Component
<lightning:tab label="test1" id="tabId">
JS Controller
component.find("tabId").set('v.label', 'test2');
Can you help me with this?
Best Answer
UPDATE
It turns out that the
label
attribute inlightning:tab
is of typecomponent[]
and not text. And thus it was not being set in the first place when trying to set thelabel
directly.So to set the
label
, you will need to get thelabel
component and then set thevalue
attribute on it. Note that you will need to useaura:id
instead ofid
as mentioned in the docs.This will yield you the results.
OLD ANSWER
While not completely sure about your use case, but re-rendering the tab will achieve for what you are looking for.
On Component, declare attributes as below:
Then, use it as below to render the tab:
And then in your JS, doing something will let you change the
label
.