簡體   English   中英

角度將管道數組分配給變量

[英]Angular assign piped array to variable

我有一些代碼:

  <tr *ngFor="let article of articles
    | tableFilter: { id: searchResult, title: searchResult, author: searchResult }
    | orderBy:sortType:sortReverse
    | paginate: config"
      (change)="updateCollectionSize()">...</tr>

我的問題很簡單。 完成所有管道后,如何將articles數組分配給新變量?

如果您確實希望將修改后的列表作為模板中的變量,則可以這樣做:

 <div *ngIf="articles
    | tableFilter: { id: searchResult, title: searchResult, author: searchResult }
    | orderBy:sortType:sortReverse
    | paginate: config 
    as filteredArticles">

    <tr *ngFor="let article of filteredArticles">...</tr>
  </div>

基本上,只需將所有內容包裝在ngIf中,然后使用“ as”(或“ let”關鍵字)來聲明包含已過濾文章的模板變量。

就是說,正如@trichetriche在評論中已經說過的那樣,您可能應該在Typescript中做這種事情。 在不了解更多數據結構以及如何修改數據的情況下,我無法為您提供幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM