Model not changing on selecting file
See original GitHub issueHTML Code:
<script type="text/ng-template" id="closeImageTemplate.html">
<button type="button" class="btn btn-default" ng-click="removeImage(pic)">
Remove
</button>
</script>
<div ngf-select="" ngf-drop="" ng-model="uploads" ngf-multiple="true" ngf-accept="'image/*'" ngf-capture="'camera'" ngf-drag-over-class="{accept:'dragover', reject:'dragover-err', delay:100}" ngf-keep="true" ngf-keep-distinct="true" ngf-reset-on-click="false" ngf-reset-model-on-click="false" ngf-allow-dir="false" class="hlyt-drop-box" ngf-drop-available="dropAvailable">Select File
<span ng-show="dropAvailable">or Drop</span></div>
<br>
<div class="hlyt-preview-section">
<span class="hlyt-preview-img" ng-repeat="pic in uploads">
<img ngf-src="pic" ngf-accept="'image/*'" popover-template="closeImageTemplate" popover-trigger="click" popover-placement="top">
</span>
</div>
// Image Upload
$scope.$watch('uploads', function(uploads) {
$scope.formUpload = false;
if (uploads != null) {
for (var i = 0; i < uploads.length; i++) {
$scope.errorMsg = null;
(function(file) {
uploadFile(file);
})(uploads[i]);
}
}
});
$scope.removeImage = function(pic) {
console.log($scope.uploads); // always empty
}
The code only enters the $watch function when the page first loads. It doesn’t when I select a file. I’ve tried using $watchCollection, $watch with equality, but nothing seems to work.
Morever, in the removeImage function, the $scope.uploads value is always empty.
Using latest version available in bower, 5.0.9. Please Advice.
Issue Analytics
- State:
- Created 8 years ago
- Comments:20 (4 by maintainers)
Top Results From Across the Web
Change the "No file chosen" - html - Stack Overflow
I would like to change the "No file chosen" text to something else, like "No video chosen" or "Choose a video please". I...
Read more >Change "Choose file" and "No file chosen" texts in a <input ...
I have an ASP.NET Core 5 web app with an action to upload a file. This is de model: public class UploadViewModel; {;...
Read more >Save Simulink model - MATLAB save_system - MathWorks
In the Model File pane of the Simulink Preferences dialog box, under Change Notification, select Saving the model. This preference is on by...
Read more >Managing Changes and Updates to SketchUp Files within ...
After your model file opens in SketchUp, make your changes to the model file and select File > Save. When you switch back...
Read more >Using files from web applications - Web APIs - MDN Web Docs
Accessing selected file(s) on a change event. It is also possible (but not mandatory) to access the FileList through the change event.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi… Don’t have time to create a jsfiddle right now, I’ll try creating it when I get the time… but in my case I figured out that the model was getting added to some other scope even though there is no scope nesting… I’m yet to figure out which scope. It’s definitely not the parent scope. So effectively, the model is getting added to some other scope and the function defined in ngf-change is getting called against a different scope (I don’t know if it’s always like that since I’m pretty new to angular)
Yep, using $parent works.
My code is in an ng-switch block. It’s my fault for not considering the scope.