I've read countless articles on this / questions on Stack Overflow, as well as the documentation, but I don't seem to be able to find an answer for this anywhere.
Basically I have the following directive:
angular.module('diDirectives', []).
directive('ExampleElement', ['$rootScope', '$timeout', function($rootScope, $timeout) {
return {
priority: 0,
restrict: 'C',
template: '<div class="ExampleElement"></div>',
link: function(scope, el, attrs) {
function finish(){
$('.ExampleElement').fadeOut(function(){
$(this).remove();
});
}
//$('<div class="ExampleElement"></div>')
//.appendTo('body')
//.hide()
//.fadeIn(function(){
$timeout(finish, 10000);
//});
}
}
}]);
That looks for an element called ExampleElement and then fades it out and removes it from the DOM after 10 seconds. The problem is that the element HAS to already exist on the page... what I want to do is make it so that the directive adds the element to the page for me (see the commented out jquery code to append it to the body).
But I can't seem to figure it out. I've read into $compile and other things, but almost all examples seem to deal with adding a directive to another directive or other template, rather than just adding it when the code is run...
Can anyone show an example of how to do this?
Update: One idea I had was doing this was:
diApp.run(function ($state, $rootScope, $log, $location) {
$rootScope.$state = $state;
$('body').append('<div class="loading-overlay"></div>')
.hide()
.fadeIn(function(){
// CALL DIRECTIVE LINK FUNCTION???
});
});