I'm trying to creating a basic javascript animation with ngAnimate
, but the event / animation doesn't fire when an element is added.
Essentially, I'm adding an element with a class test
on click, which should change its color to green. But the color does not change and the alert doesn't fire. This is a basic example pulled from the tutorial so it should be working.
Any idea what could be going wrong?
html:
<body ng-controller="MainController as Ctrl">
<h1>Hello Plunker!</h1>
<span ng-click="Ctrl.append()">Add</span>
</body>
app.js:
var app = angular.module("myApp", ['ngAnimate']);
app.controller("MainController", function(){
this.append = function(){
var li = $('<li></li>').addClass('test').text("hey");
$('body').append(li);
};
});
app.animation(".test", function(){
return {
enter: function(element, done) {
alert(element);
console.log(element);
$(element).css('color', 'green');
done();
},
leave: function(element, done) { }
};
});
Example in a plunker: http://plnkr.co/edit/alTUxFw4twL4LAaCDZvG?p=streamer