I have created a file upload directive that displays an alert box when the file(s) have uploaded successfully. However, when the user first navigates to the page, the alert box is shown with the .ng-hide-add class, which fades the alert-box out.
I could use ng-if to prevent this initial behaviour, but because it creates its own scope and I have some elements within it, I cannot use this workaround.
I found a potential solution here, but neither options seem to work for me (inline style with display none or using ngClass).
HTML:
<div ng-show="success" class="alert-box success animate fadeInLeft">Files Successfully Uploaded!</div>
Directive:
app.directive('fileUpload', ['$fileUploader', '$timeout',
function($fileUploader, $timeout){
return {
restrict: 'E',
replace: true,
scope: {
showQueue: '=',
imagesOnly: '='
},
templateUrl: 'templates/files/upload.html',
link: function(scope, element, attrs) {
scope.success = false; // initially setting the variable to false to hide element
uploader.bind('success', function(event, xhr, item, response) {
scope.success = true;
$timeout(function() {
scope.success = false;
}, 2000);
});
// ...
}
}
}]);