Changing the heading color based on a condition with uib-accordion

I am currently utilizing angular-ui in conjunction with my AngularJS application. One component I have on my page is an accordion (uib-accordion) element, where the content, name, and state (opened/closed) are bound to an array in the controller.

The desired behavior I am aiming for is as follows: when the tab is closed, the heading should appear gray, and when it is opened, it should display in a different color. How can I achieve this based on the value of filter.isOpened? I attempted using ng-class like so:

 ng-class="{'panel-blue-heading': filter.isOpened}"

However, I was unsuccessful in implementing it. Below is a simple fiddle that may provide some insight. Thank you!

var app = angular.module("myApp", ['ui.bootstrap']);
app.controller('testCtrl', ['$scope', function($scope) {
  $scope.filtersInfo = [{
    filterParams: [1, 2, 3, 4],
    filterName: "testFilter",
    isOpened: true
  }];
}]);
.panel-default {
  border: 0;
}

.panel-group {
  margin-bottom: 5px;
}

.panel-body {
  padding: 5px;
}

.panel-default >.panel-heading {
  color: black;
}

.panel-blue-heading >.panel-heading {
  background-color: #42c6eb;
  color: black;
}

.container {
  padding: 10px;
  border-radius: 15px;
  border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>

<div ng-app="myApp">
  <div ng-controller="testCtrl" class="container">
    <div ng-repeat="filter in filtersInfo">
      <uib-accordion close-others="oneAtATime">
        <div is-open="filter.isOpened" uib-accordion-group              class="panel-default">
          <uib-accordion-heading>
            {{ filter.filterName }}
          </uib-accordion-heading>

          <div>
            ...MY CONTENT...
          </div
        </div>
      </uib-accordion>
    </div>
  </div>
</div>

Answer №1

Great job, you were so close:

<uib-accordion close-others="oneAtATime" ng-class="{'opened': filter.isOpened}" id="my-accordion">

To style the .panel-heading that is generated by the directive, use this CSS code:

#my-accordion.opened .panel-heading {
  background-color: blue;
}

By specifying the ID, only the intended panel headings will have a blue background.

var app = angular.module("myApp", ['ui.bootstrap']);
app.controller('testCtrl', ['$scope', function($scope) {
  $scope.filtersInfo = [{
    filterParams: [1, 2, 3, 4],
    filterName: "testFilter",
    isOpened: true
  }];
}]);
#my-accordion.opened .panel-heading {
  background-color: blue;
}

.panel-default {
  border: 0;
}

.panel-group {
  margin-bottom: 5px;
}

.panel-body {
  padding: 5px;
}

.panel-default >.panel-heading {
  color: black;
}

.panel-blue-heading >.panel-heading {
  background-color: #42c6eb;
  color: black;
}

.container {
  padding: 10px;
  border-radius: 15px;
  border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>

<div ng-app="myApp">
  <div ng-controller="testCtrl" class="container">
    <div ng-repeat="filter in filtersInfo">
      <uib-accordion close-others="oneAtATime" ng-class="{'opened': filter.isOpened}" id="my-accordion">
        <div is-open="filter.isOpened" uib-accordion-group              class="panel-default">
          <uib-accordion-heading>
            {{ filter.filterName }}
          </uib-accordion-heading>

          <div>
            ...MY CONTENT...
          </div
        </div>
      </uib-accordion>
    </div>
  </div>
</div>

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

Safari does not stop the scrolling of the <body style="overflow-y: hidden"> tag

Welcome to this simple HTML page <body style="overflow-y: hidden"> ... </body> This page is designed to prevent scrolling by using the CSS property overflow-y: hidden. While this functionality works as intended on most browsers, it does ...

Locating function definitions in etags using Emacs

I find syntax check in js2-mode to be quite effective. However, there are times when I wish to name a function "delete" or "new" even though it may not be the best practice. Js2-mode often flags this as an error. Is there a way to use built-in keywords as ...

Having difficulty leveraging the full capabilities of the Jquery.load() function

I'm currently facing an issue where the results I want to display to the user are not filtering properly based on their selection. I've been using GET on the same page (users.php?rid=) to process this, but for some reason, it seems to be loading ...

Tips for Managing Disconnection Issues in Angular 7

My goal is to display the ConnectionLost Component if the network is unavailable and the user attempts to navigate to the next page. However, if there is no network and the user does not take any action (doesn't navigate to the next page), then the c ...

Error message: The Modelviewer is unable to load the local file, displaying the message "Unauthorized to access local resource."

For my WebAR project, I am utilizing Google's ModelViewer. In my vue.js project, I have a component that loads the model using the <model-viewer> attribute. My goal is to set the src attribute of the model-viewer to the absolute path of the .gl ...

AngularJS: Customize form elements based on model type

I need to work with an Angular model that contains ConfigValues. This is essentially a Dictionary object passed from C# which looks something like this: { Name: "Config Name", Value "True", Type: 0 // boolean } Some of these values are boolean, ...

Steps for saving both checked and unchecked checkbox values in Firebase

I have a set of objects that I am using as initial data in my Ionic 3 application: public interests = [ { name: 'Travel', checked: false }, { name: 'Animals', checked: false }, { name: 'Theatre', checked: false ...

I am attempting to create a password validation system without the need for a database, using only a single

Help Needed: Trying to Create a Password Validation Website <script language="Javascript"> function checkPassword(x){ if (x == "HI"){ alert("Just Press Ok to Continue..."); } else { alert("Nope... not gonna happen"); } } ...

Tips for showcasing devnagri script from user input on a php webpage

On one of my PHP pages, I have changed the font for input to Devnagri. Now, I need to display it on the next PHP page and also insert it into MySQL. The first page, index.php, contains the following details... <table width="535" height="54" border=" ...

Efficiently handling multiple responses in Express.js per single request

Currently exploring Node.js and working on a bot utilizing Dialogflow. I am aiming to establish a straightforward process: Step 1: Dialogflow sends a POST request with parameter param1 Step 2: My application replies with a waiting message (e.g., "your re ...

"Encountered an error: Unable to access property 'fn' on an undefined object within the Wordpress

I attempted to recreate the steps outlined in this blog post Create A Realistic Self-solving Rubik's Cube With Three.js on a Wordpress page. However, I encountered the following error Uncaught TypeError: Cannot read property 'fn' of undefine ...

Expansive picture within a Bootstrap container

How can I create a wide image within a Bootstrap container? <div class="container-fluid"> <div class="container"> <img data-layout="wide" src="big-image.jpg" alt="Big image" class="embedded_image"> </div> </div& ...

Ensure that only non-alphabetic characters are accepted in keypress validation, while allowing all other keys to function

Restriction: Only numbers, spaces, and plus symbols are allowed in the text box $('#value').bind('keypress', function (e) { if ($('#value').val().length == 0) { if (e.which == 32) { //space bar e.preven ...

Exploring Node.js: A Comparison of Promises and Callbacks Versus Synchronous

I have knowledge about Promises and Callbacks. However, I am curious to know, Is it considered good practice to use synchronous modules such as Sync, synchronize, etc.,? What are the appropriate scenarios or use cases for using Sync and in which scenario ...

Exploring methods for looping through deeply nested object attributes in AngularJS

Here is a sample JSON that I'm working with. I tried using ng-repeat="(key, value) as shown below to achieve the desired output, but it's not functioning correctly. <table border="1"> <tr ng-repeat="(key, value) in data1"> ...

The Angular application is only functional after the page has been refreshed

I am currently working on a Wordpress website that includes a page featuring an Angular application. Initially, everything was functioning properly. However, I recently encountered an issue where the Angular app fails to load when I access the page through ...

What is the best way to output neat and tidy JavaScript code from a custom view helper in Rails

As I was working on my update.js.erb file using Rails 3, I realized that I was repeating a lot of code. To simplify things, I attempted to move it all into a helper function. However, I encountered an issue where the helper was not producing clean JavaScri ...

How to automatically adjust select view in AngularJS as model value is updated

My select element is structured as follows: <select data-ng-model="transaction.category" class="form-control" data-ng-options="category.name group by category.parent for category in categories" required> </ ...

Tips for displaying errors in React applications

Having trouble troubleshooting React (16.13.0) as I am not receiving any useful errors, just this message: Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for more info or switch to the non-minified dev en ...

Using CSS3, you can apply multiple backgrounds to an unordered list with one set

Currently, I am in the process of working on a unique Wordpress template. One of the challenges I am facing is figuring out how to incorporate three background images for each <li> element in the dynamically generated navigation menu. Here are two ex ...