Koten
Koten

Reputation: 679

AngularJS animate element disappearing

in the example below you can see that when item is added to the list it is doing the fade animation and then disappearing, I want it to have bootstrap style after animation, It is probably conflicting with bootstrap css but I can't figure out which css code exactly is doing that.

code

plunkr.co

html

  <head>
    <link rel="stylesheet" href="https://bootswatch.com/lumen/bootstrap.min.css">
    <link rel="stylesheet" href="style.css"/>
    <script src="https://code.angularjs.org/1.5.0-rc.0/angular.js"></script>
    <script src="https://raw.githubusercontent.com/angular/bower-angular-animate/master/angular-animate.min.js"></script>

    <script src="script.js"></script>
  </head>

  <body>
    <div ng-controller="Controller">
    <input type="button" value='click' ng-click="addItem()"/>
    <input type="button" value="delete" ng-click="deleteItem()"/>
    <input type="text" ng-model="filterText"/>
    <table class="table table-striped table-hover center-table">
      <tr class="fade" ng-repeat="item in (filtered=(items | filter:filterText))">
        <td>{{item.name}}</td>
      </tr>
    </table>
    </div>
  </body>

</html>

js

    var app=angular.module('App',['ngAnimate']);
app.controller('Controller',function($scope){
  $scope.items=[];

  $scope.addItem=function(){
    $scope.items.push({'name':'cgagaga'})
  };
  $scope.deleteItem=function(){
    $scope.items.splice(0,1);
  }
});

css

.fade.ng-enter {
    transition: 2s linear all;
    background-color: lightgreen;
    opacity: 1;
}

/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active {
    background-color: #f3f3f3;
    opacity: 1;
}

.fade.ng-leave {
    transition: 1s linear all;
    background-color: #FF6F79;
    opacity: 1;
}

.fade.ng-leave.ng-leave-active {
    opacity: 0;

Upvotes: 1

Views: 1312

Answers (1)

Sim
Sim

Reputation: 385

Change the name of fade animation to something else (e.g. fade1) and change opacity in .fade1.ng-enter to 0.

.fade1.ng-enter {
   transition: 2s linear all;
    background-color: lightgreen;
    opacity: 0;
}

.fade1.ng-enter.ng-enter-active {
    background-color: #f3f3f3;
    opacity: 1;
}

.fade1.ng-leave {
    transition: 1s linear all;
    background-color: #FF6F79;
    opacity: 1;
}

.fade1.ng-leave.ng-leave-active {
    opacity: 0;
}

Upvotes: 2

Related Questions