angular.module('myApp')
.directive('fileModel', ['$parse', 'uploadService','messageService','CONF', function ($parse, uploadService,messageService,CONF) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function () {
var file = element[0].files[0];
var fd = new FormData();
fd.append('file', file);
console.log(fd)
self.isDisabled = true;
ParkingService.uploadImage(fd).then(
function (response) {
response = JSON.parse(response);
element[0].files[1] = response;
console.log(response)
if (response.message !== 'ERROR') {
// self.image = response.result;
messageService.toasterMessage(CONF.TOASTER_TOP_RIGHT,CONF.TOASTER_SUCCESS,"Success Upload File");
}
else {
messageService.toasterMessage(CONF.TOASTER_TOP_RIGHT,CONF.TOASTER_ERROR,response.result);
}
}
);
scope.$apply(function () {
modelSetter(scope, element[0].files);
});
});
}
};
}]);
how can the variable "response" be assigned a value?
element[0].files[1] = response;
This method works in older versions of Safari and Chrome but it might not be fully supported in newer versions of Chrome.