React.js to pain HTML:如何将imageupload.HTML React代码转换为angular


onChange(e) {
const file = e.target.files[0];
Storage.put('example.png', file, {
contentType: 'image/png'
})
.then (result => console.log(result))
.catch(err => console.log(err));
}

imageupload.html

<input type="file" accept='image/png' onChange={(evt) => this.onChange(evt)}/>

因此以下代码处于react中。如何在angular 6 HTML文件中编写以下代码?主要是如何用HTML编写这个onChange={(evt) => this.onChange(evt)}部分?

请参阅原始代码:https://docs.amplify.aws/lib/storage/upload/q/platform/js#browser-上传

HTML也有onchange事件属性,您只需调用HTML中的函数即可:<input type="file" accept='image/png' onchange="onChange(this.value)"/>

从我提到的SO Post直接复制粘贴

<input 
type="file"
id="file"
(change)="handleFileInput($event.target.files)"
>

因此,我们所需要做的就是让它与您的代码一起工作:

<input 
type="file"
id="file"
(change)="onChange($event)" 
>

请注意(change)现在略有不同。

最新更新