I have a directive which at the end of everything else it does, appends a new dom element that was created in memory to the body using the $compile
method in this way
app.directive('transitionBackground', function ($compile) {
return {
restrict: 'E',
link: function(scope, elem, attrs) {
...lots of code...
function compile () {
$compile(_stageElement)(scope).appendTo("body");
animate();
}
function animate() {
console.log($(".newElement"));
}
}
When the log function happens, the new element selector returns an empty array, however when I use the console in my browser to log the same selector I get the new element as expected. When I take the compile piece off I cannot even do that, so I know the compile method is working. Why can't the animate function see it?