【问题标题】:*ngIf not working inside the Modal*ngIf 在 Modal 中不起作用
【发布时间】:2017-11-09 23:25:54
【问题描述】:

我在一个按钮上使用了 *ngif,当从 ng-select 中选择项目但它不起作用时,该按钮将变为 false 并实现

这是按钮代码

  <button *ngIf="switch" (click)="productSaveInCart()" type="button" class="col  matbuton " mat-button>
          ADD to Cart
        </button>

这是Modal的全部代码

  <ng-template #template>
  <div class="modal-header">
    <h4 class="modal-title pull-left">{{modaldata.i.i}}</h4>
    <button type="button" class="close btn pull-right" aria-label="Close" (click)="modalRef2.hide()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    <mat-card style="margin: 0; ">
      <img height="400px" style="width: 110%" mat-card-image [src]="modaldata.i.t || '../../assets/images/noimage.png'">
      <mat-card-footer class="row">

        <h4>Extra prep. time: 1hr</h4>

        <ng-select [allowClear]="true" [items]="items" [disabled]="disabled" (data)="refreshValue($event)" (selected)="selected($event)"
          (removed)="removed($event)" (typed)="typed($event)" placeholder="No Date selcted">
        </ng-select>
        <div *ngFor="let item of list ">
          <h4 class="col">{{item.n}}</h4>
          <app-dropdowns #child class="col" [listdata]="item"></app-dropdowns>
        </div>
        <button *ngIf="switch" (click)="productSaveInCart()" type="button" class="col  matbuton " mat-button>
          ADD to Cart
        </button>
      </mat-card-footer>
    </mat-card>
  </div>

</ng-template>

【问题讨论】:

  • 打字稿控制switch在哪里?

标签: angular typescript angular2-template ngx-bootstrap


【解决方案1】:

试试这个:

(selected)="selected($event);switch=true"

你可以这样使用 hidden:它应该可以工作

[hidden]="switch"

【讨论】:

  • 你能解释一下这背后的逻辑吗?
  • 在选择事件上,您可以将开关设置为“true”,因此按钮添加到购物车将可见
  • 我知道......但是如果我在我的 component.ts 文件中更改它为什么它不可见
  • 尝试全局声明变量开关,或者使用 [hidden] 它在这种情况下完美运行。我会更新答案
猜你喜欢
  • 2017-04-20
  • 2023-02-08
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多