I looked at this question where it says:
When do you prefer ng-if vs. ng-show / ng-hide?
"For example, if you linked a click handler to one of the child elements when ng-if evaluates to true, that element will be removed from the DOM and your click handler will no longer work, even after ng-if later evaluates to true and displays the element You will need to bind the handler again.
What does reconnecting a handler mean? In this example, the function associated with ng-click works even when deleting and adding an item.
<tr ng-if="!useUserLoginTemplate" class="showRowAnimation"> <td>Template</td> <td> <input type="file" file-model="loginTemplateFile"> <span class="btn btn-primary" ng-click="uploadLoginTemplateFile()">Upload</span> </td> </tr>
I cannot access the file using $ scope.loginTemplateFile, as I do with versions without ng-if if.
Link function to the file model directive:
link: function(scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind('change', function(){ scope.$apply(function(){ modelSetter(scope, element[0].files[0]); }); }); }
What's going on here?
angularjs angularjs-directive
user2483724
source share