单击按钮列表中的按钮后打开每个div

时间:2017-10-04 13:47:14

标签: javascript html angular typescript

如何实施操作以打开与每个div相关联的每个button

我有html

  <ol *ngFor="let g of guides">
    <button type="button" class="form-control" (click)="open(g)">{{g.description}}</button>
    <div [hidden]="!canOpen" style="text-align: center">test</div>
  </ol>
</div>

哪个变量canOpen是整个component

1 个答案:

答案 0 :(得分:0)

我认为这可以帮到你:

模板面:

<button (click)="openAll()">Toggle Div</button>

<ol *ngFor="let g of guides">
    <button type="button" class="form-control" (click)="open(g)">{{g.description}}</button>
    <div [hidden]="!canOpen || openAllDiv" style="text-align: center">test</div>
</ol>

组件方:

openAllDiv = false;
openAll() {
    this.openAllDiv = !this.openAllDiv;
}