files array in upload file with angular 4 -




i select file in template this:

 <input type="file" #fileupload [(ngmodel)]="myfile" name="myfile" (change)="filechange(fileupload.files)" /> 

then in component use function manipulate object:

filechange(event){ console.log( event); this.myfile = event[0];} 

compilation ok , no errors, error in browser:

error error: [object object] @ viewwrappeddebugerror (core.es5.js:8410) @ callwithdebugcontext (core.es5.js:13475) @ object.debughandleevent [as handleevent] (core.es5.js:13053) @ dispatchevent (core.es5.js:8602) @ core.es5.js:9213 @ htmlinputelement.<anonymous> (platform-browser.es5.js:2651) @ zonedelegate.webpackjsonp.../../../../zone.js/dist/zone.js.zonedelegate.invoketask (zone.js:424) @ object.oninvoketask (core.es5.js:3881) @ zonedelegate.webpackjsonp.../../../../zone.js/dist/zone.js.zonedelegate.invoketask (zone.js:423) @ zone.webpackjsonp.../../../../zone.js/dist/zone.js.zone.runtask (zone.js:191) 

and

error error: uncaught (in promise): invalidstateerror: failed set 'value' property on 'htmlinputelement': input element accepts filename, may programmatically set empty string. error: failed set 'value' property on 'htmlinputelement': input element accepts filename, may programmatically set empty string. 

in fact can see object contains selected file, still error.

enter image description here

you cannot change value of file upload input javascript security reasons. without plunkr or it's hard say, think error happening here: this.myfile = event[0]; quick check set temporary variable instead of this.myfile.

edit: need remove ngmodel, , change argument of filechange "event" , not fileupload.files. should work.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -