If you're looking for a solution that works in production mode, I've created a directive that can help with your file upload needs. Here's how you can use it:
<input ng-upload-change="fileChanged($event)" />
In your controller:
$scope.fileChanged = function($event){
var files = $event.target.files;
}
Don't forget to include the directive in your code:
angular.module("YOUR_APP_NAME").directive("ngUploadChange",function(){
return{
scope:{
ngUploadChange:"&"
},
link:function($scope, $element, $attrs){
$element.on("change",function(event){
$scope.$apply(function(){
$scope.ngUploadChange({$event: event})
})
})
$scope.$on("$destroy",function(){
$element.off();
});
}
}
});
No need for attributions - this code is in the public domain.
Just keep in mind that if a user selects a file, closes the input, and then selects the same file again, the change function won't trigger. To address this issue, I've developed a more comprehensive directive that replaces the input each time it's used. You can find it on github here:
https://github.com/dtruel/angular-file-input/tree/master