The dynamic addition of the active class is malfunctioning

I have dynamically added a class using AngularJS, but it seems to not be functioning correctly. As I am new to AngularJS, I would appreciate any suggestions to resolve this issue. Below is my HTML code:

<div class="col-md-15 col-sm-3" ng-repeat="data in plan">
            <div class="panel panel-green" ng-class="{true: 'active'}[{{data.price}} == {{amount}}]">
                <div class="panel-heading" align="center"> <span class="{{data.logo}} custom-icon" ></span>
                    <h5 class="panel-text">{{data.title}}</h5>
                </div>
                <div class="panel-body">
                    <div class="price-container">
                        <span class="dollar">$</span>
                        <span class="price">{{data.price}}</span>
                        <span class="terms">p/m</span>
                    </div>
                    <div class="panel-text"><p>{{data.text}}</p>
                    </div>
                    <div class="start-button" align="center">
                        <label class="btn btn-default">
                            <input type="radio" name="price" ng-model="amount" ng-value="{{data.price}}"  ng-click="addPayment(amount)">
                        </label>
                    </div>
                </div>
            </div>
        </div> 

Below is my Angular controller for reference:

appControllers.controller('AccountSettingController',['$scope', 
    'Title','$http', function($scope,Title,$http) {
        //default Selected plan
    $scope.amount = 47;
        $scope.plan= [
             {
                "logo"  :   "glyphicon glyphicon-user",
                "title" :   "Let's Start",
                "price" :   47,
                "text"  :   "For powerful small teams of up to 25. A set and forget low fixed rate."
            },
            {
                "logo"  :   "glyphicon glyphicon-home",
                "title" :   "Growing Places",
                "price" :   87,
                "text"  :   "Supporting your growth. Teams of 26 to 50 'Growing places'."
            },
            {
                "logo"  :   "glyphicon glyphicon-book",
                "title" :   "Team Effort",
                "price" :   167,
                "text"  :   "Together we are better. Team effort 51 to 100 and climbing."
            },
            {
                "logo"  :   "glyphicon glyphicon-credit-card",
                "title" :   "Bigger Biz",
                "price" :   397,
                "text"  :   "For organizations of 101 to 250. Fixed rate with allowance for scaling."
            },
            {
                "logo"  :   "glyphicon glyphicon-tower",
                "title" :   "Megacorp",
                "price" :   1,
                "text"  :   "Tailored for teams greater than 250. Corporate, multi-site & franchise."
            }
            ];  
}]);

Answer №1

Switch it to that

ng-style="{'highlighted':data.value == total}"

Answer №2

Explanation of Syntax

  <div ng-class="{value1:'class1'}[condition]"></div>

 <div ng-class="condition?'class1':'class2'"></div>

 <div ng-class="'class1':condition"></div>

Make a modification to your condition, avoid using {{ }} in this context.

 <div class="panel panel-green" ng-class="{true:'active'}[(data.price == amount)]" >

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

The step-by-step guide on passing arguments and fetching results from Angular UI Bootstrap Modal through Components

I am facing a simple scenario where I have defined a modal as a component and opened that modal using `uiModal.open`. However, when I try to pass custom data to the modal using "resolve" in the open method and arguments in the controller constructor, the d ...

Is there a way to transfer textbox value to ng-repeat in AngularJS?

1) The Industry dropdown menu corresponds with a code textbox. Depending on the selected industry, the code will change accordingly. 2) There is a dynamic feature to add or delete Movie Names and Directors' names. In this table, there are three colu ...

The CSS transition is failing to revert to its original state after being combined with animations

My goal is to create a loading animation using CSS transitions and animations. I have managed to achieve the initial loading effect by scaling with transition and then animating it to scale out on the x-axis. However, when attempting to transition back to ...

HTML input field that shows a hint text when selected

Is there a way to create a text box that shows a hint when clicked on? For example, you can see this feature by clicking on the address text box in the following link: ...

How to modify the background color of a <td> element using CSS and PHP

I am working on a PHP code snippet that populates a table from a MySQL database. <?php while($res = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>".$res['id']."</td>"; ...

The hover functionality fails to activate when a z-index is applied

My issue revolves around 2 divs: one containing a link and the other a box-shaped container. The link is set with position:fixed; causing it to fly over the container div. To resolve this, I attempted to assign a negative z-index value to the link, but unf ...

Organizing the dropdown menu in alphabetical order

I am facing an issue with the following element <li id="li_15" class="dropdown dropdown-alpha highlighted" style=""> <label class="description" for="element_15">Name <span id="required_15" class="required">*</span></labe ...

Looking to retrieve the name of an article by its ID using asynchronous methods in Symfony 2.8. How can this be accomplished?

Hello everyone, I'm currently seeking a solution to retrieve the name of a product when a user enters the product ID into an input field. Here's what I have tried with JavaScript: function showHint(str) { if (str.length == 13) { $.ajax({ ...

Styling with CSS: Changing the Background Color of Text

Looking for a solution to apply line-height to text without affecting the background color? Check out the code snippet below and share your ideas if you have any. Thanks! .nb-semnox-impact-grid { display: block; font-size: 6 ...

Setting up jsonReader for jqGrid Configuration

I am having trouble displaying data in my Jqgrid. The Json data is coming from a web server, so I am attempting to format it using Jsonreader as a function. Could someone please help me identify any mistakes? Thank you in advance. Here is the code for the ...

Tips for creating a cohesive group of HTML elements within an editable area

Imagine having a contenteditable area with some existing content: <div contenteditable="true"> <p>first paragraph</p> <p> <img width='63' src='https://developer.cdn.mozilla.net/media/img/mdn-logo-s ...

Scraping the web with Python: Selenium HTML elements may differ from what is shown in the inspect tool

In my current academic project, I am facing an issue with scraping news articles from websites. The problem arises when parsing HTML code in Python because the code obtained from the page source is different from what is shown in the Inspect Element tool. ...

How to enhance the design with a box-shadow for a :after pseudo element

One of the challenges I'm facing involves a CSS design with a div called .testimonial-inner that has an arrow created using the :after pseudo element. The issue is making them appear as one cohesive element, especially when applying a box-shadow. Her ...

Using Jquery to Submit a Form by Clicking a Button

Trying to implement a verification process on a Shopify e-commerce site where users have to confirm their country before proceeding to checkout. Initially used JavaScript's confirm(), but now experimenting with JQuery UI to incorporate HTML in the pop ...

Annoying AngularJS Scrolling Problem

I am facing an issue with a Container that loads multiple views <md-content flex id="content"> <div ng-view></div> </md-content> One of the loaded views has the following structure: <div layout="column" id="selection-whit ...

Retrieve several values with a limit of 1 in SQL

Consider the following table structure: ID | ident | product 1 | cucu1 | 99867 | 2 | kkju7 | 88987 | 3 | sjdu4 | 66754 | 4 | kjhu6 | 76654 | 5 | cucu1 | 98876 | Running the query: SELECT ident,COUNT(*) FROM sales WHERE status=? AND team=? AND DATE(da ...

There seems to be an issue with ngOptions in Angular as it is

Calling all angularjs experts for assistance... Currently integrating cake with angular. Utilizing a rest controller to enable communication and retrieve options in a serialized json format as displayed below Attempting to populate dropdown options: &l ...

Is there a way to align the navigation menu options to the right side of the navbar?

I'm having trouble aligning the options in the navbar to the right side. Can anyone help me identify where I'm going wrong in my code? Here is the snippet I'm working with: <div> <nav class="navbar navbar-expand-lg navb ...

What could be causing the malfunction of my Superfish menu in Firefox?

I am currently experimenting with the Superfish jQuery plugin to improve a drop-down menu on my website. Unfortunately, in Firefox browser (v. 21.0), the drop-down menu does not open when hovering over it as expected. However, it works fine in Chrome and O ...

Retrieve the HTML content of all children except for a specific child element in jQuery

Is there a way to utilize jQuery/Javascript for selecting the HTML content of the two <p> elements in the initial <div class="description? I'm open to using Regex as well. This specific jQuery selection is being executed within Node.js on a c ...