In your template:
<input type="file" onchange="angular.element(this).scope().onFileChange(this)">
In your JS:
$scope.onFileChange = function (fileEl) {
var files = fileEl.files;
var file = files[0];
var reader = new FileReader();
reader.onloadend = function(evt) {
if (evt.target.readyState === FileReader.DONE) {
$scope.$apply(function () {
$scope.something = JSON.parse(evt.target.result);
});
}
};
reader.readAsText(file);
};
"onchange" instead of "ng-change", because it looks like Angular doesn't support binding things with ng-change on file upload input controls.
This was stolen almost verbatim from a co-worker's code. It might be Chrome-specific. If someone who knows me sees this, all credit is due to this coworker. And it's all due to him in any event anyhow. ;)