![](/img/trans.png)
[英]I am trying to send an email via angular. Am I approaching this in the correct manner?
[英]Arraybuffer is not assinable to type string, Angular. I am trying to show uploaded image on the page
我使用了一個截圖來顯示用戶選擇的圖像。 代碼有效,但在編輯器上我在下面顯示的行中收到錯誤。 我知道一旦我停止開發服務器並再次運行它,它就不會再編譯了,這發生了。
srcFotos: Array<string>;
onFileSelect(event, index) {
if (event.target.files && event.target.files[0]) {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = e => {
alert(reader.result);
this.srcFotos[index] = reader.result; //Arraybuffer is not assinable to type string
};
reader.readAsDataURL(file);
}
}
在模板上
<img [src]="srcFotos[1]" class="img-fluid">
就像我說的代碼按預期工作一樣,我選擇了圖像,盡管出現錯誤,它仍出現在頁面上。
您可以強制編譯器將其視為帶有 as 的字符串
this.srcFotos[index] = reader.result as string;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.