gpt4 book ai didi

javascript - 去掉每个文件angular 6的文件扩展名

转载 作者:行者123 更新时间:2023-11-30 11:13:26 26 4
gpt4 key购买 nike

HTML 是在我获取文件名的地方编写的,但我想去掉文件扩展名并将文件存储在数组中并在 UI 中访问它们。

<div class="myReadingListContainer">
<div class="readingList">
My Reading List
</div>
<div class="myReadingList">
<div class="uploadWrap">
<input type="file" #file (change)="onChange(file.files)" class="fileUploadInput" />
<div class="innerText">
<img src="assets/img/my_reading_list/Add.svg" class="addIcon">
<h6 class="addFile">Add Files</h6>
</div>
</div>
<div *ngFor="let file of fileList">
<div class="selectedFile">
<div class="documentName">
{{file.name}}
</div>
<span *ngIf="file.type === 'application/pdf'">
<img src="assets/img/my_reading_list/PDF.svg" class="fileTypeImage">
</span>
<span *ngIf="file.type === 'application/vnd.ms-excel'">
<img src="assets/img/my_reading_list/Excel.svg" class="fileTypeImage">
</span>
<div class="readingStatus">
20/35 Pages
</div>
<div class="progress">
<div class="progressBar"></div>
</div>
</div>
</div>
</div>
</div>

typescript 文件是这样写的。由于我是 Angular 6 的新手,非常感谢任何帮助,在此先感谢

import { Component, OnInit } from "@angular/core";

@Component({
selector: "app-myReadingList",
templateUrl: "./myReadingList.component.html",
styleUrls: \["./myReadingList.component.scss"\]
})
export class MyReadingListComponent implements OnInit {
//localUrl: String;
fileList: any = \[\];
files: any;
constructor() {}
onChange(files: FileList) {
console.log(files);
this.files = files;
this.fileList.push(files\[0\]);
this.fileList.forEach(file => {
let temp = file.name.split(".");
file.name = temp.splice(0, temp.length - 1).join(".");
});
console.log(this.fileList);
}
ngOnInit() {}
}

最佳答案

这是在显示每个 fileList.name

时删除文件扩展名的示例代码
<div class="documentName">
{{file.name.split('.').slice(0, -1).join('.')}}
</div>

Demo同样

关于javascript - 去掉每个文件angular 6的文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52640269/

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