【发布时间】:2019-05-13 02:09:47
【问题描述】:
是否应该从角度权继承长度?以及为什么 if (fileList.length> 0) MyPostsComponent.html: 7 ERROR TypeError: Cannot read the 'length' of undefined property.
onFileSelection(event){
const fileList: FileList = event.target.filse;
if (fileList.length > 0){
const file: File = fileList[0];
this.myFire.uploadFile(file).then(data => {
//TO DO
this.notifier.display('success','Picture Uploaded!');
console.log(data['fileUrl']);
})
.catch(err => {
this.notifier.display('error', err.message);
});
}
}
在我的 html 代码上
<input type="file" (change)="onFileSelection($event)" placeholder="Upload a file" accept=".png, .jpeg, .jpg">
【问题讨论】:
-
如果以下答案不起作用,请检查
fileList包含的内容。 -
我刚刚检查过了。 @rorschach 的答案是正确的。它应该是
const fileList: FileList = event.target.files;但在检查任何对象的长度之前,您仍然需要检查null | undefined。
标签: angular typescript firebase firebase-storage