I have a fancy-textbox button component. I want to make it so that users can dynamically add new fancy-textbox , but they have different labels over the text box based on the scope variable that is unique to fancy-textbox (or maybe from the parent variable of the scope that is not shared between all fancy-textboxes ). How can I do it? I am currently using this directly in my template, showing and hiding, but I want to be able to "dynamically add additional instances of this" programmatically:
<div *ngIf="showTextBox"> <fancy-textbox labelForBox="TextBox 1"></fancy-textbox> </div>
This is good if fancy text fields are created only in the DOM in one specific area. However, I want to dynamically create components in different sections of the DOM.
<div class="container"> <div class="navsection"><input id="classname" type="text"><button (click)="createFancyButton()">Create Fancy Button</button></div> <div class="topsection"> </div> <div class="midsection"> </div> <div class="botsection"> </div> <div class="footsection"></div></div>
Given the pattern above ... assuming users enter a class name (e.g. botsection) in the text box and click the createfancybutton button, I want a " <fancy-button></fancy-button> " to be placed in the corresponding section of the page, I want to be able to dynamically “create” instances of an independent “fancy button” in different sections of the page template. I could stick to 3 ng-if statements with ng-for, although this seems impractical. Looking for a better alternative ...
UPDATE: Thus, the following steps will be performed:
1) The user enters "midsection" in the text box. 2) The user clicks the Create Fancy Button button, 3) - The <fancybutton></fancybutton> will be added under the div with the class name "midsection" -
The user can click on the same “Create Fancy Button” button to create more under it. If the user changes the input field to "topsection", then when the user clicks the "Create fancy button" button, the fancybutton component will be added under the div with "topsection".
If the user enters “news,” then a new div called “newsection” will be created under the div with the class name “container”, and the fancybutton component will be added to the div called “newsection” of the class.
angular
Rollingo
source share