angularjs - Angular: how to listen for response that you yourself don't make? -
in angular, there way listen response request don't make? i'm implementing file upload node.js, , i'm submitting form programmatically:
html:
<form enctype = "multipart/form-data" action = "/blah/fileupload" method = "post" id = "upload_file" > <input type="file" onchange="angular.element(this).scope().onfileselect(event)" name="bulk_uploads" /> </form>
angular controller:
$scope.onfileselect = function(event) { var form_elem = document.getelementbyid('upload_file'); form_elem.submit(); }
the issue submitting form in fashion not return promise, , if submit form so:
$http.post('/blah/fileupload', { files : event.target.files })
then there no way uploaded files once hits node server (e.g. req.files empty).
is there way listen server's response 'blah/fileupload' submitting form programatically i'm doing, or going wrong way?
note: i'm hoping not use interceptors api sake of performance. if there's not major performance hit, please let me know!
there 2 main advice: 1) use external angular file upload library, example ng-file-upload 2) subscribe submit
event controller:
document.getelementbyid('upload_file').addeventlistener('submit', your_handler)