Failed to set indexed property to "FileList": index property setting tool is not supported .v

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 to set the answer in this variable?

element[0].files[1] = response;

he works in safari or older chrome. but does not support new chrome.

+4
source share
1 answer

Both Chrome and Firefox now prohibit the installation of new indexes in NodeList and FileList. I suspect this is due to recent changes to make such "massive" structures more compatible in general with JavaScript and is the general direction browsers are heading.

Running in non-strict mode returns behavior, but is not possible in a reconfigured JavaScript environment - or, probably, desirable.

FileList const files = Array.from(element[0].files) const files = [...element[0].files] ( , ).

0

Source: https://habr.com/ru/post/1686809/


All Articles