简体   繁体   English

打开另一个扩展面板时如何关闭一个扩展面板(角垫)?

[英]How to close one Expansion Panel when the other is opened(Angular Mat)?

I'm trying to close one expansion panel when the other is opened.我试图在打开另一个扩展面板时关闭一个扩展面板 I know that by default it's set to multi="false" and it works absolutely fine with multiple expansion panel used inside one accordion but I'm only using one panel and I couldn't find a way to make it work.我知道默认情况下它设置为multi="false"并且在一个手风琴内使用多个扩展面板时它工作得非常好,但我只使用一个面板,我找不到让它工作的方法。 I'm still a newbie.我还是个新手。

Image on this link此链接上的图片

HTML Code: HTML 代码:

<mat-accordion>
      <mat-expansion-panel>
        <mat-expansion-panel-header>
          <div
        class="col text-center"
        [ngClass]="{
          'text-green': transactionDTO.txn_type == 'CREDIT',
          'text-red': transactionDTO.txn_type == 'DEBIT',
          'text-cyan': transactionDTO.txn_type == 'WITHDRAWAL'
        }"
      >
        {{ transactionDTO.txn_type }}
      </div>
      <div class="col text-center" style="font-size: 20px;">
        {{ transactionDTO.created_date | date: "dd-MMM-yyyy" }}
      </div>
      <div class="text-center col-xl">
        {{ transactionDTO.txn_status }}
      </div>
      <div class="col text-center" style="font-size: 20px;">
        <span
          [ngClass]="{
            'text-green': transactionDTO.txn_type == 'CREDIT',
            'text-red': transactionDTO.txn_type == 'DEBIT',
            'text-cyan': transactionDTO.txn_type == 'WITHDRAWAL'
          }"
          ><ng-container
            *ngIf="
              transactionDTO.txn_type == 'WITHDRAWAL' ||
                transactionDTO.txn_type == 'DEBIT';
              else credit
            "
            >-</ng-container
          ><ng-template #credit>+</ng-template
          >{{ transactionDTO.txn_amount | currency: "USD":"":"1.2-2" }}</span
        >
      </div>
      <div class="col text-center" style="font-size: 20px;">
        {{ transactionDTO.final_amount | currency: "USD":"":"1.2-2" }}
      </div>
      <div
      class="col text-center downarrow"
      [ngClass]="{ arrow: showHistory }"
      (click)="fetchHistoryDetails()"
    >
      {{
        transactionDTO.payment_method == "Wire transfer"
          ? transactionDTO.txn_id
          : transactionDTO.payment_method
      }}
    </div>
        </mat-expansion-panel-header>
        <mat-panel-description>
        <div
          class="row detailsRow no-gutters justofy-content-around align-items-center"
          *ngIf="showHistory"
          marketplace-transaction-history-details
          [transactionType]="transactionDTO.transactionType"
          [userType]="'BUYER'"
          [currentStatusStep]="transactionDTO.currentStatus"
        ></div>
        </mat-panel-description>
      </mat-expansion-panel>
    </mat-accordion>

CSS: CSS:

.mat-expansion-panel-header{
    font-family: "Lato", Arial, Helvetica, sans-serif;
    color: #162e4d;
}
.mat-accordion .mat-expansion-panel:last-of-type{
    margin-bottom: .3rem;
    border: 1px solid #c0c8d4;
    box-shadow: none;
    border-radius: 0;
}
.detailsRow{
    width: -webkit-fill-available;
}

Typescript:打字稿:

import { Component, Input, OnInit } from "@angular/core";
import { TransactionHistoryDTO } from "@shared/dto/transaction-history-dto";
@Component({
  selector: "[marketplace-transaction-history-item]",
  templateUrl: "./transaction-history-item.component.html",
  styleUrls: ["./transaction-history-item.component.scss"],
})
export class TransactionHistoryItemComponent implements OnInit {
  @Input() transactionDTO:TransactionHistoryDTO;
  showHistory = true;
  constructor() {}

  fetchHistoryDetails() {
    this.showHistory = !this.showHistory;
  }
  ngOnInit(): void {
    // console.log(this.transactionDTO);
  }
}

As mentioned in the first comment, i just see only one expansion-panel in the code you posted.正如第一条评论中提到的,我在您发布的代码中只看到一个扩展面板。 Anyway looking at the image you linked, if you have more expansion panels and you want just one to be axpanded at time, you can just go like this in the HTML:无论如何查看您链接的图像,如果您有更多扩展面板并且您希望每次只扩展一个,您可以在 HTML 中这样做:

<mat-expansion-panel class="" [expanded]="step === 0" (opened)="setStep(0)">
</mat-expansion-panel>

<mat-expansion-panel class="" [expanded]="step === 1" (opened)="setStep(1)">
</mat-expansion-panel>

<mat-expansion-panel class="" [expanded]="step === 2" (opened)="setStep(2)">
</mat-expansion-panel>

While in your .TS :在您的 .TS 中:

step :number = 0; //global variable

setStep(index:number){
    this.step = index;
}

Hope it helps :)希望能帮助到你 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM