Last active
August 13, 2023 09:52
-
-
Save GreenFlag31/a11570f3e93fd9176539d904c2b79c70 to your computer and use it in GitHub Desktop.
app component HTML :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<!-- Add a TemplateRef on ng-template --> | |
<ng-template #view> | |
<div class="modal-container"> | |
<div class="title"> | |
<h2>How to create component dynamically in Angular ?</h2> | |
</div> | |
<div class="content"> | |
<p class="current"> | |
This is the first method. First method is to use a ViewContainerRef | |
with a Template Ref. You create the view contained within the | |
TemplateRef, then create the modal component and inject the view. | |
</p> | |
</div> | |
<div class="footer"> | |
<button (click)="close()">Close</button> | |
</div> | |
</div> | |
</ng-template> | |
<!-- Pass the TemplateRef to the method we will create --> | |
<button class="template" (click)="openModalTemplate(view)"> | |
Open modal with TemplateRef | |
</button> | |
<!-- Second approach --> | |
<button (click)="openModalComponent()">Open modal with a component</button> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment