How to expand dynamically angular material panel

Use the expanded attribute of the mat-expansion-panel element and set it to true when the condition is met.
In the following example a filter pipe is used
and the result is placed in the filteredBookmarks variable which is checked in the condition – [e…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Adrian Matei

Use the expanded attribute of the mat-expansion-panel element and set it to true when the condition is met.
In the following example a filter pipe is used
and the result is placed in the filteredBookmarks variable which is checked in the condition - [expanded]="filteredBookmarks.length === 1" :

<mat-expansion-panel
  *ngFor="let bookmark of bookmarks | bookmarkFilter: filterText as filteredBookmarks; index as i"
  [expanded]="filteredBookmarks.length === 1">
  <mat-expansion-panel-header *ngIf="i<15">
    <div class="p-3">
      <h5 class="card-title">
        <a href="{{bookmark.location}}"
           [innerHTML]="bookmark.name | slice:0:100 | highlightHtml: filterText"
           target="_blank"
           (click)="addToHistoryService.promoteInHistoryIfLoggedIn(true, bookmark)"
           (auxclick)="addToHistoryService.onMiddleClickInDescription(true, $event, bookmark)"
        >
          {{"see innerhtml"}}
        </a>
        <sup class="external-link-hint"><i class="fas fa-external-link-alt"></i></sup>
      </h5>
      <h6 class="card-subtitle mb-2 text-muted url-under-title"
          [innerHTML]="bookmark.location | slice:0:120 | highlightHtml: filterText"
      >
        {{"see innerhtml"}}
      </h6>
    </div>
  </mat-expansion-panel-header>

  <ng-template matExpansionPanelContent>
    <app-bookmark-text [bookmark]="bookmark" [showMoreText]="true"
                       (click)="addToHistoryService.onClickInDescription(true, $event, bookmark)"
                       (auxclick)="addToHistoryService.onMiddleClickInDescription(true, $event, bookmark)">
    </app-bookmark-text>
  </ng-template>
</mat-expansion-panel>

Project: codever - File: hot-keys-dialog.component.html

See it in action at www.codever.land:

Dynamically expand angular material panel

Shared with ❤️ from Codever. Use 👉 copy to mine functionality to add it to your personal snippets collection.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Adrian Matei


Print Share Comment Cite Upload Translate Updates
APA

Adrian Matei | Sciencx (2022-11-28T14:52:49+00:00) How to expand dynamically angular material panel. Retrieved from https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/

MLA
" » How to expand dynamically angular material panel." Adrian Matei | Sciencx - Monday November 28, 2022, https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/
HARVARD
Adrian Matei | Sciencx Monday November 28, 2022 » How to expand dynamically angular material panel., viewed ,<https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/>
VANCOUVER
Adrian Matei | Sciencx - » How to expand dynamically angular material panel. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/
CHICAGO
" » How to expand dynamically angular material panel." Adrian Matei | Sciencx - Accessed . https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/
IEEE
" » How to expand dynamically angular material panel." Adrian Matei | Sciencx [Online]. Available: https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/. [Accessed: ]
rf:citation
» How to expand dynamically angular material panel | Adrian Matei | Sciencx | https://www.scien.cx/2022/11/28/how-to-expand-dynamically-angular-material-panel/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.