Angular 2 - 在按钮上单击n [创建部分[在Html]中n次

时间:2018-03-16 09:03:46

标签: angular typescript append

  <div class="schedule-time">
      <span>Add Schedule Time <span class="adr" (click)="AddNewSchedule()">+</span></span>
........
</div>



     <div *ngFor = "let i of OpenNewSchedule">
          <div  class="time-cl">
            <div class="time-ch">
              <div class="from-time" (click)="addOpentime()">
                  <input type="date" class="form-control hide-dt">
                  <span class="fdst">Open Time</span>
                  <span class="sdst">{{Opentime}}</span>
              </div>
              <div class="to-time" (click)="addCloseTime()">
                  <input type="date" class="form-control hide-dt">
                  <span class="fdst">Close Time</span>
                  <span class="sdst">{{Closetime}}</span>
              </div>
              <!-- <a  class="time-del"><i class="fa fa-trash"></i></a> -->
            </div>
         </div>
       </div>

.TS

AddNewSchedule(){
for(var i =0; i<10; i++){
this.OpenNewSchedule = true;
  }
}

我需要重复添加div OpenNewSchedule ,现在它只添加一次,每个添加的div必须是不同的值

如何做到这一点?

2 个答案:

答案 0 :(得分:2)

试试这个

public OpenNewSchedule = [];

AddNewSchedule() {
    this.OpenNewSchedule.push('some value');
}


<div *ngFor = "let i of OpenNewSchedule">

答案 1 :(得分:1)

试试这个:

public OpenNewSchedule = [];

AddNewSchedule() {
    this.OpenNewSchedule.push('Element');
}


<div *ngFor = "let element of OpenNewSchedule">Element to display : {{element}}</div>