I am making a simple file upload script and have only been able to find working examples that are based off of an input
's (change)
event. I.e. - https://www.thepolyglotdeveloper.com/2016/02/upload-files-to-node-js-using-angular-2/
<input type="file" id="userfile" class="form-control"
(change)="fileChangeEvent($event)" name='userfile'>
This works. And that's great.
However if I try to bind a file input to an ngModel it doesn't work.
template
<form class="form-signin" (ngSubmit)="onSubmit(fileForm.value)" #fileForm="ngForm">
<input type="file" id="userfile" class="form-control"
[(ngModel)]="fileUpload.userfile" name='userfile'>
<input type="text" id="random" class="form-control"
[(ngModel)]="fileUpload.random" name="random">
<button class="btn btn-lg btn-primary btn-block" type="submit">Upload File</button>
</form>
component.ts
onSubmit(data){
console.log("Submitted");
console.log(data);
}
Only the data set in the random
input will show up. No files placed in the file input will show up, only as (undefined) in both my ngModel and printing out the data from onSubmit(data)