-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slice is not a function ng-file-upload.js:489 #1139
Comments
Can you post your code here? or better create a jsfiddle so we can figure out what's going wrong. |
Same here. Using latest build. Happens just in html, controller not involved. |
You guys need to create a jsfiddle or describe steps to reproduce. |
Coming across this same issue as well. Seems like @chrisschaub is correct, just happening in the html without even getting to the controller. Here is a form sample where I am seeing it:
Here are the versions I am using:
|
That html snippet works on the demo page. Create a jsfiddle to show the error. |
Ok, here's the issue. The DEMO has a ng-model called "file" which is local to the form. If you create a scope variable in your controller, say $scope.data.file and try to do ng-model="data.file", you will get the slice error. |
Did that still no error. |
The error is caused by the following line:
This is definately a real issue though a tricky one to reproduce. slice is undefined when prevFiles is actually trying to find a single file not an array. This happends for me after I save the result of an image upload to my database and try to replace the uploaded image afterwards. this is a simple fix that has worked for me:
Just test if the existing files model is an array or not before trying to slice it. I am not sure if this code change has any reprecussions but I'm working on a PR for it now and it's fixed my problem running a local copy of the code. |
Let me know if there is a more graceful fix you'd prefer for this problem and I'm happy to refactor.
@sean-stanley How do you replace the server files on the client side? Unless you create a Blob object from the server data you should not replace it or assign it to the file model since it is not a file or blob. |
I could probably add a check to detect assigning none file values to the model. |
Maybe I'm using the directive wrong then. Here is what I'm doing. A picture is uploaded to cloudinary from the ngf-select directive and the request returns a bunch of useful info. On success I pass just the full url of the image on cloudinary's server as well as it's public name to the file object as 'result' and 'url' keys. Using the ngf-src directive, I load the image from the url cloudinary returned. Then, if the user wants to replace the image with another one, they click the ngf-select directive button and select a new image. Once that is clicked, the error would occur because ng-model had a value that was not an array. They may try and replace the image after it has been saved to the database in which case it is saved as a basic object in MongoDB not a File or Blob. All I needed was the cloudinary url anyway as I use their service for all the resizing and stuff I need. Would you like to see a code sample? Or a live demo? I should have a prototype live online of my app in a couple days. |
I would try to add the logic to the plugin to ignore any non file objects in the model, but that might screw up the ngf-keep or mixing it with other directives so I might return an error if there is a non file object in the model. For you case just use |
Should be fixed at version 10.0.3 |
Uncaught TypeError: (((ngModel && ngModel.$modelValue) || attr.$$ngfPrevFiles) || []) slice is not a function
that error is throwed just after choose an image.
The text was updated successfully, but these errors were encountered: