html - 隐藏的上传表单不会在 Angular 中注册更改事件
问题描述
我重构了我的上传表单。想要拥有这个精美的照片图标,但现在不工作。在我拥有此代码并且一切正常之前:
<div class="row user-profile">
<div class="col-md-4">
<img class="img-responsive" *ngIf="userApi.path" src="{{createImgPath(userApi.path)}}" />
<img class="img-responsive" *ngIf="!userApi.path" src="{{createImgPath(usersImages/userApi.user.imageUrl)}}" />
<form enctype="multipart/form-data">
<div id="upload">
<label class="btn btn-default btn-file">
Browse<input (change)="uploadPhoto()" #fileInput class="btn btn-back" type="file" name="photo" style="display:none" />
</label>
</div>
</form>
</div>
我删除标签元素并添加图标照片元素以及我包含的所有内容到带有类编辑的 div 元素。这是我在 html 中的代码:
<div class="col-md-4 profile-pic">
<img class="img-responsive" *ngIf="userApi.path" src="{{createImgPath(userApi.path)}}" />
<img class="img-responsive" *ngIf="!userApi.path" src="{{createImgPath(usersImages/userApi.user.imageUrl)}}" />
<div class="edit">
<form enctype="multipart/form-data">
<i class="material-icons">
photo_camera
</i>
<input (change)="uploadPhoto()" #fileInput type="file" name="photo" style="display:none" />
</form>
</div>
</div>
.profile-pic:hover .edit {
display: block;
}
.edit {
position: absolute;
right: 25;
top: 0;
display: none;
cursor: pointer;
}
.edit i{
background-color:rgba(218, 213, 213, 0.884);
border: 1px solid bleck;
color: grey;
border-radius: 50%;
padding: 5px;
}
在我的 ts 文件中,我有方法 uploadPhoto。这是在我的 ts 文件中:
@ViewChild('fileInput',{static: true}) fileInput: ElementRef;
uploadPhoto(){
var nativeElement:HTMLInputElement = this.fileInput.nativeElement;
this.userApi.upload(nativeElement.files[0]);
}
解决方案
你有没有试过用你的 i 元素来包围你的输入元素,就像以前的标签元素一样?
推荐阅读
- html - 即使添加了类,也没有应用 Scss/sass 样式
- python - 如何将 XML 提取到具有重复行的表中
- firebase - Flutter firebase 应用程序与对话流连接时显示错误
- python - 我正在尝试在 cassandra 查询中传递参数,但使用 python 时出现错误
- python - Pandas 使用索引名称和列名称应用函数
- c# - 公共函数返回一个列表c#
- html - 造型类星体元素按钮工具
- gitlab - run a gitlab-ci stage only if changes or previous fail
- postgresql - 不同的索引用于具有不同 companyid 的相同查询
- android - Firebase firestore database returns null, the Query Snapshot value is empty but I have data stored on firestore, why is this returning null?