As I said in the question, what am I trying to achieve is the equivalent of code like these in Angular:
jQuery
$(document).ready(function(){ var windowHeight = $(window).height(); var headerHeight = $('header').height(); var footerHeight = $('footer').height(); var contentHeight = $('.content').height(); var paginationHeight = $('.pagination').height(); var footerMarginTop = (windowHeight - headerHeight - footerHeight) - (contentHeight + paginationHeight); $('footer').on('content.loaded', function() { if(footerMarginTop > 0) { $(this).css('margin-top', footerMarginTop + 'px'); } } });
When preparing the document, I have to set the upper upper edge of the footer based on calculating the height of the other elements after loading the page content. Thinking in jQuery is easy to do, but in Angular, I just did not find any other way than translating it directly so using the directory
Angular way
angular.module('myApp', []).directive('FooterMargin', ['$window', '$document', function($window, $document){ return { restrict: 'A', link: function(scope, element, attrs) { var windowHeight = $window.innerHeight; var headerHeight = $document[0].getElementById('header').offsetHeight; var footerHeight = $document[0].getElementById('footer').offsetHeight; var paginationHeight = $document[0].getElementById('pagination').offsetHeight; var contentHeight = $document[0].getElementById('content').offsetHeight; var footerMarginTop = (windowHeight - headerHeight - footerHeight) - (contentHeight + paginationHeight); scope.$on('content.loaded', function(){ if(footerMarginTop > 0) { attrs.$set('style', 'margin-top: ' + footerMarginTop + 'px'); } } }); } }; }]);
I added identifiers to my elements to get them in Angular, but even if it works, it seems to me that this is not a very good way to do this, and it is also difficult to compile it.
I can't use jQuery in this project, and I used Angular for another directive for events that are easier to get with it (like modals and dropdowns) in a satisfactory way
Can you help me figure out how to approach this better than Angular?