danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

ng-model with ng-if different scope #2137

Open moparlakci opened 4 years ago

moparlakci commented 4 years ago

Just to let you know if you wrap your ng-file-upload with an ng-if it will create a child scope and the ng-model binding will not work.

It will work but it will only change the model in the child scope and the 'parent' the actual scope will not know about it.

Use ng-show instead..

$scope.files = null;

<div ng-if="isReady">
       <label>Choose file</label> 
       <input type="file" ngf-select ng-model="files" ngf-multiple="true" ngf-pattern="'*/*'" ngf-accept="'*/*'" ngf-max-size="20MB" />
</div> 
console.log($scope.files);
null
<div ng-show="isReady">
       <label>Choose file</label> 
       <input type="file" ngf-select ng-model="files" ngf-multiple="true" ngf-pattern="'*/*'" ngf-accept="'*/*'" ngf-max-size="20MB" />
</div> 
console.log($scope.files);
[{}, {}, {}}]