In my web application I have a \"Terms and Conditions\" popup that opens by link click in the footer (so it\'s a core component). Popup comprises of several tabs, each of th
You can wait for the user to click on the link and as soon as Click Event occurs, load the required component in the view. Things to keep in mind:
The terms and conditions component needs to be defined as Entry level component for it's Module or the module where it is used.
entryComponents: [
ChildComponent
],
Make sure to refer to the placeholder in your component and attach the terms and condition component dynamically.
and
@ViewChild('viewContainerRef', { read: ViewContainerRef }) VCR: ViewContainerRef;
and create the component dynamically:
createComponent() {
let componentFactory = this.CFR.resolveComponentFactory(ChildComponent);
let componentRef: ComponentRef = this.VCR.createComponent(componentFactory);
let currentComponent = componentRef.instance;
currentComponent.selfRef = currentComponent;
// to track the added component, you can reuse this index to remove it later
currentComponent.index = ++this.index;
// providing parent Component reference to get access to parent class methods
currentComponent.compInteraction = this;
}
there is an example for you here: https://add-or-remove-dynamic-component-parent-child.stackblitz.io