Angular 如何使用ngModel和ng2文件上载获取文件名而不是路径?
我需要在选择时获取输入的文件名并将其保存到数据库中,但它似乎只显示文件的伪路径Angular 如何使用ngModel和ng2文件上载获取文件名而不是路径?,angular,angular-ngmodel,ng2-file-upload,Angular,Angular Ngmodel,Ng2 File Upload,我需要在选择时获取输入的文件名并将其保存到数据库中,但它似乎只显示文件的伪路径 //component.html <div class="col s12 file-field input-field" style="margin-left: -10px"> <div> <input type="file" name="cat" [(ngModel)]="subf" ng2FileSelect [uploader]="uploader2"/&g
//component.html
<div class="col s12 file-field input-field" style="margin-left: -10px">
<div>
<input type="file" name="cat" [(ngModel)]="subf" ng2FileSelect [uploader]="uploader2"/>
</div>
<div class="file-path-wrapper" style="margin-right: -10px">
<input class="file-path validate" name="banner" ngModel placeholder="Seleccione una Imagen" type="text">
<label for="banner" style="margin-left: 10px">Banner</label>
</div>
</div>
我得到的输出是
C:\fakepath\image.png
,我只需要image.png
你应该有一个带有点击事件的按钮
<input style="display: none" type="file" (change)="onFileChanged($event)" #fileInput>
<button type="button" (click)="fileInput.click()">Select File</button>
<input style="display: none" type="file" (change)="onFileChanged($event)" #fileInput>
<button type="button" (click)="fileInput.click()">Select File</button>
onFileChanged(event) {
console.log( event.target.files[0].name) );
}