javascript - How to use ng-enter & leave css animations inside of directive -


just getting started nganimate here please bare me...

i have ng-repeat element inside of angular directive animate.

now, i've added angular-animate file document & nganimate dependency app... element however, doesn't seem getting ng-* animation classes applied it. thought ng-repeat directive automatically aware of nganimate? missing? placing inside of directive somehow force me use $animate directly?

http://plnkr.co/edit/vovutq1bzjop2lbwdk8a?p=preview

index.html

<!doctype html> <html ng-app="app">    <head>     <link data-require="bootstrap-css@*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />     <script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>     <script data-require="angular-animate@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular-animate.js"></script>     <script src="script.js"></script>   </head>    <body>     <alerts></alerts>   </body>  </html> 

script.js

'use strict';  var app = angular.module('app', ['nganimate']);  app.run(function(alert) {   alert.success('hello world!'); });  app.factory('alert', function($timeout) {    var options = {     duration: 3000   };    var counter = 0;    var alerts = [];    function createalert(type, message) {     var alert = {       type: type, message: message, id: counter++     };      alert.promise = $timeout(function() {       removealert(alert.id);     }, options.duration);      alerts.push(alert);   }    function removealert(id) {     var alert = find(id);     if (alert && !alert.deleting) {       alert.deleting = true;       var index = alerts.indexof(alert);       // cancel automatic timeout       $timeout.cancel(alerts[index].promise);       // remove alerts array       alerts.splice(index, 1);     }   }    function clear(alert) {     if (alert) {       removealert(alert.id);     } else {       (var = 0; < alerts.length; i++) {         removealert(alerts[i].id);       }     }   }   function find(id) {     (var = 0; < alerts.length; i++) {       if (alerts[i].id === id) {         return alerts[i];       }     }   }    function success(message) {     createalert('success', message);   }    return {     alerts: alerts,     success: success,     clear: clear   } });  app.directive('alerts', function(alert) {   return {     restrict: 'ae',     templateurl: 'alerts.html',     scope: true,     controller: function($scope) {       $scope.close = function(a) {         alert.clear(a);       };     },     link: function(scope) {       scope.alerts = alert.alerts;     }   } }); 

alerts.html

<div ng-repeat="alert in alerts" class="alert alert-{{alert.type}}">   <button type="button" class="close" ng-click="close(alert)">&times;</button>   {{alert.message}} </div> 

style.css

.ng-leave {   transition: 1s linear; }  .ng-leave {   opacity: 1; }  .ng-leave-active {   opacity: 0; } 

thanks, trying understand how works

oh. didn't import style.css!


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -