[英]Update rxjs from angular material table responsive directive
在此stackblitz 演示中,有一個 Angular 12 項目,可讓您創建具有可擴展行的響應式材料表。 您在表 html 標記中使用“matTableResponsive”指令。
該項目的 rxjs 版本是 6.5.3。
我正在嘗試在我的項目中使用此代碼,該項目使用 rxjs 版本 7.5.5 和 Angular 14。
我導入了所有內容,嘗試使用該指令,但它根本不起作用。
我檢查了包含此 function 的“mat-table-responsive.directive.ts”中的代碼:
ngAfterViewInit() {
combineLatest([this.theadChanged$, this.tbodyChanged$])
.pipe(
mapTo({ headRow: this.thead.rows.item(0)!, bodyRows: this.tbody.rows }),
map(({ headRow, bodyRows }) => ({
columnNames: [...headRow.children].map(
headerCell => headerCell.textContent!
),
rows: [...bodyRows].map(row => [...row.children])
})),
takeUntil(this.onDestroy$)
)
.subscribe(({ columnNames, rows }) =>
rows.forEach(rowCells =>
rowCells.forEach(cell =>
this.renderer.setAttribute(
cell,
'data-column-name',
columnNames[(cell as HTMLTableCellElement).cellIndex]
)
)
)
);
}
這個 function 使用mapTo ,它適用於 rxjs 6.5.3 但在版本 7.5.5 中已棄用:
我可能是錯的,但我相信這就是為什么該指令根本不適用於我的項目的原因。
有人可以幫我更新這個 function 以在最新的 rxjs 版本中工作嗎? 我知道我必須按照圖片的建議將 mapTo 替換為 map ,但我不知道該怎么做。
mapTo(true)
變成map(() => true)
mapTo({ headRow: this.thead.rows.item(0),: bodyRows. this.tbody,rows }),
變成map(() => ({ headRow: this.thead.rows.item(0),: bodyRows. this.tbody,rows })),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.