[英]Dynamically added <input> not being rendered
I have a string which holds a form that I want to dynamically render. 我有一个字符串,其中包含我想要动态呈现的表单。
When the user clicks "Add Step", my template string is added to a list and rendered with an ngFor
. 当用户单击“添加步骤”时,我的模板字符串将添加到列表中并使用
ngFor
渲染。 The problem is that the input doesn't render, only the <h3>
tag. 问题是输入不呈现,只有
<h3>
标记。
Before button click: 点击按钮之前:
After - no input is rendered on screen or in the html: 之后 - 屏幕上或html中没有呈现任何输入:
ts: TS:
scenarioTemplate = `
<div id="content">
<h3>Name</h3>
<input name="{{i}}" [ngModel]="i">
</div>`;
steps = [];
addScenarioStep() {
this.steps.push(this.scenarioTemplate);
}
html: HTML:
<form #myForm="ngForm">
<fieldset ngModelGroup="inputs" #inputs="ngModelGroup">
<ng-container *ngFor="let step of steps; let i = index">
<div [innerHTML]=step attr.stepId="{{i}}"></div>
</ng-container>
</fieldset>
</form>
<button id="addStepBtn" type="button" class="btn btn-light" (click)="addScenarioStep()">Add Scenario Step +</button>
<div id="content">
<h3>Name</h3>
<input name="{{i}}" [ngModel]="i">
</div>
in the template, not the TS. 在模板中,而不是TS。
this.steps.push(newElem);
do 做
this.steps = [...this.steps, newElem];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.