Html 角度8:动态添加Div
下面是我的HTML代码。Html 角度8:动态添加Div,html,angular,typescript,angular8,Html,Angular,Typescript,Angular8,下面是我的HTML代码。 <div class="row" style="padding-bottom: 5%;"> <div class="col-md-12" id="HolidayDiv"> <div class="form-group row justify-content-md-center m-b-10"> <label class="col-md-4 text-md-
<div class="row" style="padding-bottom: 5%;">
<div class="col-md-12" id="HolidayDiv">
<div class="form-group row justify-content-md-center m-b-10">
<label class="col-md-4 text-md-right col-form-label">
<div>HOLIDAY NAME</div>
<div><input type="text" name="firstname" placeholder="" class="form-control"></div>
</label>
<label class="col-md-4 text-md-right col-form-label">
<div>HOLIDAY DATE</div>
<div>
<div class="input-group date" data-provide="datepicker">
<input type="text" class="form-control">
<div class="input-group-addon">
<span class="far fa-calendar-alt"></span>
</div>
<i class="fas fa-lg fa-fw m-r-10 m-l-5 m-t-10 text-grey fa-indent"></i>
</div>
</div>
</label>
</div>
</div>
<!-- end #content -->
<!-- end col-10 -->
</div>
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'CustomerProfileAdd',
templateUrl: './CustomerProfileAdd.html',
styleUrls: ['./CustomerProfileAdd.css']
})
export class CustomerProfileAdd {
active = 1;
}
因为我有几个例子,但只有As和As like,但对于division,我找不到它。如果您使用的是反应式表单,我想这段视频完全解释了如何解决这个问题:使用反应式表单。它对所有类型的表单操作都有强大的功能。使用FormBuilder构建动态数组,并单击按钮调用此方法
addRowsToTable(): void {
this.sampleTableForm = this.FormBuilder.group({ you can pass your row defintion :
yourRow[] });
let index: number = 1;
const row: FormGroup = this.fBuilder.group({
reactiveFormField1: [null, Validators.required],
reactiveFormField2: [null, Validators.required],
.....
});
this.yourrow.push(row);
index++;
}
为此,必须使用
ngFor
和数组。当您执行“array.push”操作时,Angular会将另一个元素添加到该列表中