I have created a small app in LWC where different templates are shown by following this answer. The flipping of the templates works fine, but there doesn't appear to be an obvious way to send data down the hierarchy when changing the template.
Assuming you have a main component:
import { LightningElement } from "lwc";
import loadingTemplate from "./loading.html";
import finalTemplate from "./fancyTemplate.html";
export default class HelloWorld extends LightningElement {
@track isLoading = true;
@track recordId;
render() {
return this.isLoading ? loadingTemplate : finalTemplate;
}
}
And loadingTemplate
retrieves a recordId and sends it up to the main component through an event, which then gets bound to the recordId
seen above.
How can I send the value of recordId
down to finalTemplate
upon generation? I can certainly do it with using a series of <div if:true{something}>
elements, but feel this is something better suited for the JS to handle.