【问题标题】:Hide PayPal Button隐藏 PayPal 按钮
【发布时间】:2022-01-04 12:59:19
【问题描述】:

我试图根据我的开关状态隐藏一个 PayPal 按钮。目前,一旦贝宝按钮被渲染,它就会一直停留在那里。无论开关是否重新设置为信用卡

这里是开关:

<p class="heading">Payment Method</p>
      <div class="frame flex-row flex-center">
        <button
          class="flex-column flex-center"
          (click)="paymentMethod = 'creditCard'; dismountPaypal()"
          [ngClass]="
            paymentMethod == 'creditCard' ? 'type-btn-active' : 'type-btn'
          "
        >
          Debit/Credit Card
        </button>
        <button
          class="flex-column flex-center"
          (click)="paymentMethod = 'paypal'; renderPaypal()"
          [ngClass]="paymentMethod == 'paypal' ? 'type-btn-active' : 'type-btn'"
        >
          PayPal
        </button>
      </div>

这是按钮本身:

 <div>
      <div #paypalRef></div>
    </div>

在我的 component.ts 文件中,我有这个来呈现按钮,当在开关中点击 paypal 时会调用此函数:

 @ViewChild("paypalRef", { static: true }) private paypalRef: ElementRef;
  renderPaypal() {
    if (this.paypalButtonRendered != true) {
      window.paypal
        .Buttons({
          style: {
            layout: "horizontal",
            color: "white",
          },
        })
        .render(this.paypalRef.nativeElement);
    }
    this.paypalButtonRendered = true;
  }

我尝试在父 div 组件和按钮本身的 div 上使用 ngIf。这只会导致按钮永远不会显示。如果付款方式是信用卡,我也尝试使用 [ngClass] snd 设置 CSS 样式不显示,但这也不起作用。我现在有点不知所措。任何帮助将不胜感激。

【问题讨论】:

  • 使用 *ngIf 并将其与布尔变量绑定。

标签: html css angular typescript paypal


【解决方案1】:

根据 paymentMethod 条件,将样式 display: none; 添加到您不想呈现的按钮。

【讨论】:

  • 评论区优先选择单行答案。
  • 我没有足够的声望点来发表评论,但感谢您的注意。当我获得特权时,我会考虑这个建议!
  • 糟糕,我的错。你现在应该有足够的积分了:D
猜你喜欢
  • 2019-08-05
  • 2015-01-14
  • 2022-11-15
  • 1970-01-01
  • 2011-11-11
  • 2019-08-27
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多