This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
ng-animation: change animation based on variable #2464
Closed
Description
When using ng-animate with ng-view, I want to use a function to change the animation.
For example:
Page
<div data-ng-view class="animate-container" ng-animate="animationSelect()"></div>
Controller
$scope.forward = true;
$scope.forwardAnimate = {enter: 'left-enter', leave: 'left-leave'}
$scope.backwardAnimate = {enter: 'right-enter', leave: 'right-leave'}
$scope.animationSelect = function() {
return $scope.forward ? $scope.forwardAnimate : $scope.backwardAnimate
}
If forward is true it animates one way, if it is false it animates a different way.
This approach doesn't seem to work. It appears that the animationSelect function is called only when the element is initially loaded. This is because the className is set at the start of the animateActionFactory function and then not updated on subsequent uses of the animation.
function animateActionFactory(type, beforeFn, afterFn) {
var ngAnimateValue = ngAnimateAttr && scope.$eval(ngAnimateAttr);
var className = ngAnimateAttr
? isObject(ngAnimateValue) ? ngAnimateValue[type] : ngAnimateValue + '-' + type
: '';
Further down a function is returned:
return function(element, parent, after) {
if (!$sniffer.supportsTransitions && !polyfillSetup && !polyfillStart) {
beforeFn(element, parent, after);
afterFn(element, parent, after);
return;
}
element.addClass(setupClass);
I am not sure if what I am trying to do is intended (or desired) functionality for angular's animation library. If it is, then moving the setting of the className into the function returned by animateActionFactory should solve the problem.
Metadata
Metadata
Assignees
Labels
No labels