AngularJS height of tabs when visible before being tabs
I have got a very strange problem.
I am new to angularjs but quite familiar with jquery.
I do program a frontend in ANgularjs, which is planned to be a singlepageApp, never to be reloaded.
I think the problem is located in Jquery or even in html itself.
The UI-Core of the page is angularui's 'Tabs'. which means these Tabs are always visible in the same size. I only want one div to get scrollbars, which is div.tab-pane. This is important for the <ul> and the <li> elemets to be always there to navigate.
The reason for not wanting more then one scrollbar is selfexplaining, imho.
Of course I do not want it only on Init but also, when the Window is resized.
To get this I did a workaround, to get all elements on 100% height concerning the innerheight of the parent element. thats my code:
index.html:
- <body ng-app="myApp" ng-controller="InitCtrl">
- <div ng-include="'views/main.html'" class="mainview" resize ></div>
- <div class="footer">my footer text, which is necessary</div>
- </body>
(reduced to the main things)
the directive "resize" is defined as
- .directive('resize', function ($window, FullSizeElement) {
-
- return function (scope, element, attr) {
-
- var w = angular.element($window);
- scope.$watch(function () {
- return {
- 'h': w.height()
- };
- }, function () {
- FullSizeElement.size(element);
- }, true);
-
- w.bind('load', function () {
- scope.$apply();
- });
- w.bind('resize', function () {
- scope.$apply();
- });
- };
- })
and the factory FullSizeElement is defined
- .factory('FullSizeElement', function() {
-
-
- function sizeHelper(el, sub){
- el.height(
- el.parent().height()
- -el.outerHeight(true)
- +el.height()
- -sub
- -prev_siblings_height_helper (el)
- )
- };
- function prev_siblings_height_helper (el){
- var returnheight = 0;
- el.prevAll().each(function(data){
- if($(this).is(":visible")){
- console.log('returnheight', el, this, $(this).outerHeight(true))
- returnheight += $(this).outerHeight(true)
- }
- });
- console.log('returnheight',returnheight, el) ;
- return returnheight;
- };
- return {
- size : function (element){
- console.log('size(element)');
- var body = $('body');
- if (element.hasClass('mainview')) sizeHelper(element, body.find('.footer').outerHeight());
- else sizeHelper(element, 0);
- element.find('div.tab-pane:visible, div.ng-isolate-scope:visible,div.tab-content:visible').each(function(index, el){
- sizeHelper($(el),0);
- });
- }
- };
- });
The main.html is
- <tabset>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-home"></i>
- </tab-heading>
-
- </tab>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-folder-open" tooltip-placement="bottom" tooltip-animation="false" tooltip="Akten"></i>
- </tab-heading>
- </tab>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-home"></i>
- </tab-heading>
- </tab>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-credit-card" tooltip-placement="bottom" tooltip-animation="false" tooltip="Kontakte"></i>
- </tab-heading>
- Kontakte
- </tab>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-euro" tooltip-placement="bottom" tooltip-animation="false" tooltip="FiBu global"></i>
- </tab-heading>
- FiBu
- </tab>
- <tab>
- <tab-heading>
- <i class="glyphicon glyphicon-wrench" tooltip-placement="bottom" tooltip-animation="false" tooltip="Einstellungen"></i>
- </tab-heading>
- some text, may be veray long
-
- </tab>
- </tabset>
On resizing the window it works perfectly, even if I fire the event manually. On loading the window it works, when the window is not focussed (chosing another tab in firefox an let 'grunt serve' reload the page).
The problem is reloading or simply loading the page, when it is focussed / visible. In this case, the <ul> element is calculated to be 240px high, which is in fact not correct, after tabs are initiated. But when it loads without beeing visible, the height of <ul> is calculated with 42px, which is correct.
I assume 240 to be the height of the <ul>, like it is without being formatted as tabs. But I have no clue, why it works, when nobody can watch it.
One thing more: when visible, firebug notifys `GET
http://localhost:9000/views/main.html`, which is of course correct. But when unvisible, it does not, although it is loaded (and used).
Any Ideas?