I have the following code:
<input onchange="angular.element(this).scope().filesChanged(this)" fileInput="controlFormCtrl.formData.episodeFile">
The file selected, will be passed to the scope, and will be accessible inside my controller in this way:
var thisScope = this;
var rootScope = $root;
var ctrlScope = $scope;
ctrlScope.filesChanged = function(elm) {
thisScope.file = elm.files[0];
}
elm.files has the following data:
lastModified: 1485109128000
lastModifiedDate: Sun Jan 22 2017 19:18:48 GMT+0100 (CET)
name:"border-image.png"
size:1353
type:"image/png"
webkitRelativePath:""
__proto__: File
However the thisScope.file is not being set.
What can I do to fix the issue?
controllerAsas i have multiple controllers nested under eachother.ctrlScope.$apply();to let angular know thatthisScopehas changed.onchangeinstead ofng-change(which isn't supported for this type of input), Angular won't have ran a $digest cycle.elm.filesisFileListwhich is not a simple array.$apply()after the file is loaded since it is an async event.