Managing active tabs simultaneously in Bootstrap and Angular

I'm looking to organize my content using a two-tab menu system. When clicking on an option in either menu, the page's contents will be filtered and displayed based on specific parameters using Angular filters. The filter functionality is working well, and the content is being displayed as expected. However, I'm encountering an issue where selecting an option from one menu makes the previously selected option inactive.

In essence, I want both tabs from each menu to remain active simultaneously.

Code Snippet

<body  ng-controller="exploreController as exploreCtrl">    
<div class="col-sm-3 sidenav"> <!--Tab Menu 1-->
<h4>Categories</h4>
<ul class="nav nav-pills nav-stacked">
    <li ng-class="{active:exploreCtrl.isSelected(0)}"><a ng-click="exploreCtrl.select(0)">New Entries</a></li>
    <li ng-class="{active:exploreCtrl.isSelected(4)}"><a ng-click="exploreCtrl.select(4)">Art</a></li>
    <li ng-class="{active:exploreCtrl.isSelected(5)}"><a ng-click="exploreCtrl.select(5)">Comics</a></li>
</ul>        
</div>

<ul class="nav nav-tabs" role="tablist" id="Tabs"> <!--Tab Menu 2-->
    <li role="presentation" ng-class="{active:exploreCtrl.isSelected(1)}" >
    <a role="tab" ng-click="exploreCtrl.select(1)">Projects</a></li>

    <li role="presentation" ng-class="{active:exploreCtrl.isSelected(2)}" >
    <a role="tab" ng-click="exploreCtrl.select(2)">Teams</a></li>

    <li role="presentation" ng-class="{active:exploreCtrl.isSelected(3)}" >
    <a role="tab" ng-click="exploreCtrl.select(3)">Professionals</a></li></ul>

<div class="tab-content">
    <ul class="media-list tab-pane fade in active">
        <li ng-repeat = "proteam in exploreCtrl.proteams | filter:exploreCtrl.filtText | filter:exploreCtrl.filtText1">
    <div class="panel-body">
    <div class="media-left media-middle">
    <!--Content-->     
    </ul>
    </div></div></div>
</body>

Javascript Logic

var app = angular.module('exploresModule',[]);
app.controller('exploreController',function() {

this.tab=1;

var proteams = [
    { //content },
this.proteams = proteams;
this.filtText = '';
this.filtText = '';
this.select = function(setTab) {
    this.tab = setTab;

    if (setTab === 0) { this.filtText = "newentry"; return}
    if (setTab === 1) { this.filtText = 'project';  return }
    if (setTab === 2) { this.filtText = 'team'; return }
};

this.isSelected = function(checkTab) {
   return this.tab === checkTab;
}
});

Answer №1

It seems like you have been using the same variable to keep track of both elements. However, a single variable can only hold one value at a time, making it challenging to monitor multiple things simultaneously.

A better approach would be to assign one variable for the vertical set of tabs and another for the horizontal set of tabs.

You can create methods such as select2() and isSelected2(), utilizing a separate variable (let's say tab2) instead of reusing the original tab variable.

For reference, you can check out this JS Fiddle demonstrating the solution in action:

https://jsfiddle.net/luisperezphd/xx85s37t/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to delete a callback from a promise object created by $q.defer() in AngularJS?

When working with AngularJS, the $q.defer() promise object has the ability to receive multiple notify callbacks without overwriting previous ones. var def = $q.defer(); def.promise.then(null, null, callback1); def.promise.then(null, null, callback2); If ...

Retrieve children of a specified node from a JSON object using JavaScript

I am in the process of developing a tool that can extract the Core Web Vitals metrics from a specified URL. By utilizing the API, I am able to retrieve a JSON object which can be accessed with JSONPath. I intend to utilize a forEach loop to populate the ...

Creating session variables in Joomla using checkboxes and AJAX

I'm currently working on implementing session variables in Joomla with AJAX when checkboxes are selected. Below is the code snippet from select_thumb.ajax.php file: $_SESSION['ss'] = $value; $response = $_SESSION['ss']; echo ...

What is the best way to implement debounce in an asynchronous function?

Is it possible to implement the debounce function with an async method? I have a specific scenario in my vue-app where I am making continuous API calls within a method and I would like to prevent this. This is the method in question: methods: { async ...

Uncovering the secrets: accessing hidden folder files in react-native-fs

I am encountering a problem when trying to access files from a hidden folder /WhatsApp/Media/.Statuses in react-native-fs. Despite granting the READ_EXTERNAL_STORAGE permission on Android, I only receive an empty array when attempting to access it using th ...

Modifying characters within a designated class definition

I'm working on integrating Isotope with a CuteNews system, and in order to make the filtering function properly, I need to include some identifiers in my class declaration for each isotope item. Link to Isotope In CuteNews, my news items can have mul ...

How can you choose all objects that are similar within an array, based on specific keys?

Is there a way to filter an array to find all objects that share similarities in certain keys, even if the values of those keys are unknown? Consider having an object structured like this: let list = [ { name: 'Adam', age: '10', u ...

Second question regarding the conversion of an Excel spreadsheet formula into JavaScript code

Hey everyone, I'm back again with another challenge. This time, I'm struggling to accurately translate an Excel Spreadsheet formula to JavaScript. Here is the Excel formula: =IF(IF($B$7=TRUE,$B$28/$B$10,$B$28/$B$5)>1,1,IF($B$7=TRUE,$B$28/$B ...

Save log discrepancies to a document

Upon completing my website for graduation, there is still one important feature I want to add. I would like to implement a script that sends the name of the website where it is installed, as well as any error messages, to my website. For instance: The fol ...

Generate a new random color in Vue.js for each user added to the list whenever the page is refreshed

I am looking to convert some jQuery code into Vue.js. The goal is to assign a random color to each user in a dynamic list every time the page is (re)loaded. Below is the original jQuery code: //RANDOM USER COLOR $(".usersElements").each(function(inde ...

Obtain data from files within a React frontend application

I have integrated an API endpoint into my NodeJS application. The purpose of this endpoint is to locate a specific file in a folder based on the filename provided in the request. Here's how I am approaching this: const fileDirectory = 'C:/Sites/p ...

Backbone.js: Navigating the Default Path Issue

I've embarked on creating my very first BB app. Progress is decent, but I've hit a roadblock. My router implementation appears as follows: var PlayersAppRouter = Backbone.Router.extend({ routes: { '': 'index', ...

Is there a way to incorporate an 'ended' feature into the .animate() function?

I'm currently working on a jQuery statement where I want to activate pointer events once the button animation is finished. However, I'm unsure how to incorporate an ended or complete function. Any suggestions on how to approach this? $('#ce ...

Using Node.js, use the `require()` function to bring in external modules

In my development of an application using Typescript that compiles into node code, I find myself favoring import statements over require. When attempting to utilize Lodash with Lodash-Deep, the official documentation suggests using: const _ = require("dee ...

Axios encounters difficulty retrieving the response data following a POST request

When using axios to post data and fetch a response, I am encountering an issue where the data is successfully posted but the response data cannot be printed. This works correctly in Postman, so I'm not sure if the problem lies with the backend or fron ...

The OnClick event is unresponsive when accessing the website on a mobile browser

I have a HTML page where I've included an onclick event in a div tag. Within this event, I'm using location.href = url to open a specific URL. Surprisingly, this works perfectly fine in a web browser but strangely doesn't work in a mobile br ...

An unexpected error occurred while working in the Studio, causing an interruption in the workflow. I encountered an unforeseen issue when launching the Sanity Start tool, resulting in an

An error occurred while trying to read properties of null. The specific property being accessed is 'jsonType'. This error was triggered at line 170029 in the file app.bundle.js. The function validateNonObjectFieldsProp attempted to access this pr ...

"Adjusting the margin for dropdowns in a Bootstrap navbar

Is there a way to customize the alignment of the bootstrap navbar drop-down? Currently, the drop down menu always starts from the right corner. I would like to set a specific starting point for the drop-down. You can view an example in this Fiddle. When ...

Exclude certain APIs from utilizing basic authentication in Fastify

I currently have two APIs set up: /auth and /no-auth. My goal is to only use basic authentication for one of them. To implement this, I am using the fastify-basic-auth plugin with fastify in a node environment. The /auth route should require authenticat ...

Converting Cyrillic characters to ASCII codes using JavaScript: A step-by-step guide

Is there a reliable method to convert characters from the CP1251 table to ASCII codes ranging from 0 to 255? So far, I have only come across the charCodeAt() function which is limited to codes up to 128. It returns a Unicode number for codes above that r ...