question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model not changing on selecting file

See original GitHub issue

HTML 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:closed
  • Created 8 years ago
  • Comments:20 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
varunacharcommented, Aug 5, 2015

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)

1reaction
erkanarslancommented, Jul 30, 2015

Yep, using $parent works.

My code is in an ng-switch block. It’s my fault for not considering the scope.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found