gpt4 book ai didi

angular - 我对长度有疑问。错误类型错误 : Cannot read property 'length' of undefined

转载 作者:搜寻专家 更新时间:2023-10-30 21:34:34 25 4
gpt4 key购买 nike

长度应该从angular right继承吗?以及为什么 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">

最佳答案

const fileList: FileList = event.target.filse;

你似乎有一个错字,这将导致 fileListundefined 因为事件的目标 definitely 不包含名为 filse

关于angular - 我对长度有疑问。错误类型错误 : Cannot read property 'length' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53735094/

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