-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ngAminate
#22
Comments
For anyone looking to incorporate ng-animate, here's what I did to accomplish it. A few things to be aware of:
First, in the function flashAlertDirective(flash, $animate, $timeout) {
return {
scope: true,
link: function ($scope, element, attr) {
var timeoutHandle, subscribeHandle, clone, parent; And: angular.module('angular-flash.flash-alert-directive', ['angular-flash.service'])
.directive('flashAlert', ['flash', '$animate', '$timeout', flashAlertDirective]); Next, update the function show(message, type) {
if (timeoutHandle) {
$timeout.cancel(timeoutHandle);
}
$scope.flash.type = type;
$scope.flash.message = message;
removeAlertClasses();
angular.forEach(flash.classnames[type], function (clazz) {
// because ng-animate destroys elements, we clone & use the original element
// ignoring the original
clone = element.clone();
parent = element.parent();
// add the clone to the parent & add the alert class
parent.append(clone);
clone.addClass(clazz);
// animate the clone
$animate.enter(clone, parent, null, function() {
clone.removeClass('hide');
});
});
// this shouldn't be needed anymore
if (!isBlank(attr.activeClass)) {
element.addClass(attr.activeClass);
}
if (!message) {
$scope.hide();
return;
}
var delay = Number(attr.duration || 5000);
if (delay > 0) {
timeoutHandle = $timeout($scope.hide, delay);
}
} Finally, update the $scope.hide = function () {
$animate.leave(clone, function() {
removeAlertClasses();
clone.removeClass(attr.activeClass);
clone.addClass('hide');
});
}; Example Markup: <div class="row">
<div class="col-md-12 col-lg-12">
<div flash-alert class="alert am-fade-and-scale hide">
<strong>You Did It!!!</strong>
<span class="alert-message">{{flash.message}}</span>
</div>
</div>
</div> Note: I am using the angular-motion from https://github.com/mgcrea/angular-motion. You can use whatever animations you want, just replace the |
AngularJS's new animating support is outstanding...
angular-flash
should leverage it.http://docs.angularjs.org/api/ngAnimate
The text was updated successfully, but these errors were encountered: