{{cell | filesize}}和 dateFormat看起来像这样 dateFormat(r-6ren">
gpt4 book ai didi

angular - 我如何在 Angular 6 中以人类可读的方式表示文件大小?

转载 作者:行者123 更新时间:2023-12-05 03:04:25 26 4
gpt4 key购买 nike

假设我在 html 中有 *ngFor="let cell of dateFormat(row)">{{cell | filesize}}</td>dateFormat看起来像这样

dateFormat(row:string){

var today = new Date(row[4]);

let latest_date = this.datepipe.transform(today, 'yyyy-MM-dd');

row['4'] = latest_date;

return row;

}

HTML:

<tr *ngFor="let row of this.UploaderService.tableData2.dataRows">
<td [ngClass]="{'active': check(row) }" (click)="listClick($event, row)"
(dblclick)="listDoubleClick($event, row)"
*ngFor="let cell of dateFormat(row)">{{cell}}
</td>
</tr>

有没有办法调用filesize仅在 row['2'] ?此刻filesize工作正常,但它会格式化所有行。我试过 dateFormat但我不确定如何使用 filesize在 typescript 中。像这样

let latest_date = this.datepipe.transform(today, 'yyyy-MM-dd');

row['4'] = latest_date;
row['2'] = here convert row['2'] using filesize;

return row;

有什么想法吗?

最佳答案

npm install ngx-filesize

在你的模块中:

import {NgxFilesizeModule} from 'ngx-filesize';



// ...

@NgModule({
// ...
imports: [
// ...
NgxFilesizeModule,
// ...
]
// ...
})

在你的组件中

{{bytes | filesize}}

*我知道这个解决方案是一个迟到的回复,但它可以帮助即将到来的开发人员:)

关于angular - 我如何在 Angular 6 中以人类可读的方式表示文件大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53031243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com