Skip to main content
10-Marble
Feb 26, 2020 4:11 PM UTC
Solved

Determining Active Tab Number as String

Regarding this post: Determining Active Tabs  

 

Using the proposed solution, when a button is pressed, I would like a label to display the current active tab number.

 

My attempt is below but this currently isn't working. Any advice would be appreciated. 

 

$scope.buttonPress = function(){
 var tabID = $scope.testClickTab();
 $scope.setWidgetProp( "label-9", "text", tabID);
}


$scope.testClickTab=function(key) {
	angular.forEach( 
 	$element.find('twx-tab'), function(value, key) {
 if(value['style']['display']=='block') console.error(key); 
 } )
};

 

tincescuAnswer
5-Regular Member
Feb 27, 2020 9:49 AM UTC

// $scope, $element, $attrs, $injector, $sce, $timeout, $http, $ionicPopup, and $ionicPopover services are available



function isHidden(el) {
 return (el.offsetParent === null)
}


angular.element(document).ready(function () {

	//$scope.ShowTabState(); 

});


$scope.ShowTabState = function() {
 var tabs = document.getElementsByClassName("tab");
 	for(i=0; i<tabs.length; i++) { 	
 if(isHidden(tabs[i]) == false) {
 	$scope.app.view.Home.wdg["label-1"].text = "Current Tab " + i;
 } 
 }
}

 

Is this the behaviour you want?

3 replies

tincescu5-Regular MemberAnswer
5-Regular Member
Feb 27, 2020 9:49 AM UTC

// $scope, $element, $attrs, $injector, $sce, $timeout, $http, $ionicPopup, and $ionicPopover services are available



function isHidden(el) {
 return (el.offsetParent === null)
}


angular.element(document).ready(function () {

	//$scope.ShowTabState(); 

});


$scope.ShowTabState = function() {
 var tabs = document.getElementsByClassName("tab");
 	for(i=0; i<tabs.length; i++) { 	
 if(isHidden(tabs[i]) == false) {
 	$scope.app.view.Home.wdg["label-1"].text = "Current Tab " + i;
 } 
 }
}

 

Is this the behaviour you want?

Translate
5-Regular Member
Feb 27, 2020 9:52 AM UTC

My approach is this.

We check in the ShowTabState what elements with the class tab are visible on the screen (in our case it will be always one). 

 

tincescu_0-1582797109009.png

 

Then we call this funtion when the button is pressed.

tincescu_1-1582797122658.png

 

 

Translate
rhudd10-MarbleAuthor
10-Marble
Feb 27, 2020 5:12 PM UTC

Hi @tincescu ,

 

Yes, that's exactly what I'm looking for, thank you very much 😁

 

Also, I appreciate the video, it helps to make communication clear and is a nice touch 🙂

 

For clarity, should anyone else use this approach, 'tab' is entered as the class for each individual tab, not for the tab object as a whole. I made this mistake initially.

 

Many thanks

Translate