Don't call ngf-change with an empty files parameter
See original GitHub issue@danialfarid What I’m seeing is that ngf-change is being called TWICE. Once when you click the button and the file chooser dialog opens and once when the dialog closes after selecting a file.
I added this to your fiddle…
$scope.upload = function (files) {
alert('called from upload. files is: ' + files);
Whatever is calling it shouldn’t call it the first time. There is no reason to call $scope.upload if files is null. This would allow me to remove the null check and simplify things greatly.
Issue Analytics
- State:
- Created 8 years ago
- Comments:20 (17 by maintainers)
Top Results From Across the Web
AngularJS: ng-change called before an select element is ...
try ng-change="ngChange" instead of ng-change="ngChange()"? I think the ngChange() is making a call. – NPToita. Dec 2, 2015 at 7:20.
Read more >Top 18 Most Common AngularJS Developer Mistakes - Toptal
Sheer size of the AngularJS can easily lead to many mistakes. In this article you will learn about most common AngularJS developer mistakes...
Read more >deploy — AWS CLI 1.27.37 Command Reference
Deploys the specified AWS CloudFormation template by creating and then executing a change set. The command terminates after AWS CloudFormation executes the ...
Read more >Makefile Tutorial By Example
The goal of Makefiles is to compile whatever files need to be compiled, based on what files have changed. But when files in...
Read more >about Functions Advanced Parameters - PowerShell
Get-Date_Func: Cannot process argument transformation on parameter ... and Set-Content cmdlets only when it's used in a file system drive.
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
2017 update:
I have a form that is set up to validate on whether or not a file was uploaded. When a user would cancel out of the dialog box, the upload field would be invalid because the ng-model had changed to null.
Since the API has since changed from the suggestions in this issue but this page is still the top result when searching “ng-file-upload change empty,” I figured I’d note my solution:
I simply hooked into the ngf-before-model-change function, set a temporary controller variable, and reset my “real” value when ngf-change was called. It looks a little like this:
form.html
controller.js
Now, the ng-model variable ctrl.file is either a real file (the user selected one in the dialog) or the file it was previously (the user cancels out of the box).
Had the same issue- Fixed it by using. Not sure if this is the correct way
<button ngf-select="" ng-model="files" ngf-multiple="false" >Upload </button>
In controller-
$scope.$watch('files', function (files) { console.log(files); if( (files != null) ){ console.log('file uploading'); } });