angular - 编辑按钮单击获取图像名称并显示使用角度选择的输入文件
问题描述
当我单击编辑按钮时,我希望能够删除“未选择文件”以添加category.ImageName 。在输入中添加了[(ngModel)]="category.ImageName"但它不起作用。
<div *ngIf="category.FileSource.length > 0; else customAvatar">
<input
formControlName="File"
id="File"
type="file"
[value]="category.ImageName"
[(ngModel)]="category.ImageName"
(change)="onFileChange($event)"/>
<img *ngIf="chnageeventimage==='true'; else changeAvatar" [src]="imageSrc || '../../../../../assets/images/camera.jpg'" style="height: 80px; width:80px">
<ng-template #changeAvatar>
<img [src]="category.FileSource" style="width:80px; height:80px;" alt="User avatar" />
</ng-template>
零件:
ngOnInit(): void {
debugger;
const categoryID: string = this.route.snapshot.queryParamMap.get('categoryID');
this.api.EditCategory(categoryID).subscribe(data =>{
console.log(data);
this.category = data;
});
}
输出
解决方案
您可以隐藏输入并自定义 div 或按钮,如下所示:
<div *ngIf="category.FileSource.length > 0; else customAvatar">
<input
id='browse'
style='width:0px'
type="file"
(change)="onFileChange($event)"/>
<button onclick="browse.click()">Upload image</button>
{{category.ImageName}}
<img *ngIf="chnageeventimage==='true'; else changeAvatar" [src]="imageSrc || '../../../../../assets/images/camera.jpg'" style="height: 80px; width:80px">
<ng-template #changeAvatar>
<img [src]="category.FileSource" style="width:80px; height:80px;" alt="User avatar" />
</ng-template>
推荐阅读
- c# - 获取形状中所有内容控件的标题列表时出错 (Word)
- sage - 如何优化我的 Sage 可约化算法的速度?
- data-structures - 随机快速排序的最坏场景是什么?
- java - 收到关于 json 的错误,我是 Android World 的新手
- python - 如何使用 Keras 创建多输入一输出 LSTM 模型?
- android - 启用后等待多长时间开始 BLE 扫描?
- sed - AIX:sed 命令删除除第一行之外的所有行的模式
- python - 在 Python 中显示虹膜数据集时出错
- scala - 在没有 RDD 的数据帧列值提取中定义隐式/显式编码的最佳实践
- java - 无法将带有连字符的 JSON 字段映射到 Java 对象字段