I have a aura component call myComponent that opens a tab with WorkspaceAPI:
myComponent
myComponent : function(component) {
var valueName = component.get("v.valueName");
var recordId = component.get("v.recordId");
var orderNumber = component.get("v.orderNumber");
var pageReference = {
"type": "standard__component",
"attributes": {
"componentName": "c__tabComponent"
},
"state": {
"c__name": valueName,
"c__id": recordId,
}
};
var workspaceAPI = component.find("workspace");
workspaceAPI.openTab({
pageReference: pageReference,
focus: true
}).then((response) => {
workspaceAPI.setTabLabel({
tabId: response,
label: "Order: " + orderNumber
});
workspaceAPI.setTabIcon({
tabId: response,
icon: "standard:orders"
});
}).catch(function(error) {
console.log(error);
});
}
The tabComponent is open in a tab and I want to closed the tab trough a button, but I tried several things to send a value to myComponent to fire this method so he can close with this code, because I don't have the value of tabId on tabComponent and also I don't have the lightning:workspaceAPI, because it's in the myComponent:
closeTab : function(component) {
var workspaceAPI = component.find("workspace");
workspaceAPI.closeTab({tabId: component.get("v.tabId")});
}
How can I close the tab with a button in tabComponent? I don't have the tabId and also the lightning:workspaceAPI, they are not parent and child also :(