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

Is there a way to access the variable value chosen from a select dropdown inside a function and then assign it to a JavaScript variable outside of the function?

Below is the HTML and JavaScript code that I am working with: function changeResult() { x = document.getElementById("dropdown-list").value; console.log((x)); } var qq; <select id="dropdown-list" onchange="changeResult()"> <option value="4 ...

Unable to include Title as a parameter in Jquery message box

Below is the HTML code I have written: <div id="dialog" title=""> <form action="" method="post"> <label>Name:</label> <input id="name" name="name" type="text"> </form> </div> This is my ca ...

AngularJS triggers the function on all controllers

I encountered a problem with a specific function in my code. The issue is that the scrollFunction continues to get triggered even when I navigate to another page. I would like to limit this functionality to only apply to a particular page within the cont ...

What is the process for adding a box shadow beneath my header?

I am currently attempting to add a box shadow under my header, similar to the design featured in the project mockup at https://github.com/RaghavMangrola/the-brighton-times. After trying to implement the following CSS property and value: .header { ...

Ways to alter formData using jQuery

For my form submission using AJAX, I utilize FormData to gather data. Here is how I collect the form's data: var data = new FormData($(this)[0]); One of the inputs on the form consists of a color value in HSV format that I need to convert to hex. Wh ...

Challenges in working with PHP, SQL, HTML, and AJAX data submission

Having encountered another issue, I've been attempting to make an AJAX script function properly, but whenever I click on it, the page reloads without updating the database field. The code I'm using has successfully worked for similar scripts on ...

Testing a custom Angular directive that encapsulates the functionality of SlickGrid

Currently, I am working on testing an angular directive that acts as a wrapper for slickgrid. 'use strict'; describe('Unit: Grid Directive', function() { var $scope; var element; beforeEach(module('grid')); beforeEac ...

Is there a way to access a controller's $scope value from a different page?

Here is a simple demonstration of Angular Routing: <li><a ui-sref="Login()">Login</a></li> <li><a ui-sref="Logout()" ng-show="!usersessionData">Logout</a></li> MyApp.js var app = angular.mo ...

How to customize GtkEntry in GTK3 with CSS to eliminate the default blue outline?

I've been working on customizing the theme of an application using Gtk3 and Css. I have successfully implemented my desired themes for the widgets by using gtk_widget_set_name and defining names in CSS. However, I am facing an issue with removing the ...

Which combination of jquery version and jquery ui version is considered the most optimal?

I am wondering what the optimal combination of jQuery version and jQuery UI version is for my project? ...

Randomly generated numerical value in input field

How can I generate a 15-digit number using JS code and then reduce it to just 5 or 6 digits in a text box? <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript ...

Using AJAX to retrieve version information via jQuery

I have a straightforward script that extracts the value of a textarea and sends it via AJAX. When I input "??" as the text, the output seems to be corrupted with strange values. However, when I log out the retrieved value before sending it, everything appe ...

Troubleshooting the issue of autoplay not functioning in HTML5 audio

I'm facing a strange issue with my code - the autoplay feature for audio is not working as expected. Typically, whenever I insert this particular piece of code into a website, the music starts playing automatically. However, it seems to be malfunctio ...

Obtaining array value in JSON and incorporating it into a datatable

I have the following JSON data: { "aaData": [ [ { "displayValue": "Home Page", "link": "http://somelink.com" }, "London", "1983" ], [ { ...

Krajee Bootstrap File Input: Easily upload files along with your form

I am facing an issue where I am unable to submit the form along with the selected files. I have tried both methods mentioned in the documentation. My requirement is to send everything together by clicking the submit button on the form. Here is the HTML co ...

Implement functionality in AngularJS to automatically switch focus to the next input field when the maximum character length is reached, and return focus to the previous input field when the

Task at Hand I am tasked with creating 3 input fields, each with a maximum character length of 5. The requirement is that when the 5th character is entered in an input, the cursor should automatically move to the next input field. Similarly, when the firs ...

Issues with Swiper functionality in Jquery Mobile

I have implemented the Swiper plugin by idangero.us along with jQuery Mobile... In this case, I am utilizing the Scroll Container Swiper for a content slider... However, I am encountering several difficulties when trying to integrate the code... You can ...

Organizing string enum in Typescript and AngularJS - Tips and Tricks

In my Typescript file, I have defined an enum called PriorityLevel: enum PriorityLevel { High = <any>'High', Normal = <any>'Normal', Low = <any>'Low'} In the HTML section, I have the following code: <b ...

The task runner explorer in VS2013 is experiencing a glitch where it fails to retain bindings after changes

I am using VS2013 with the task runner explorer extension. Is there a way to save task bindings, such as having a task run when the solution is opened, so that I can share these settings with my team through a version control system? I want to avoid havi ...

The Dropdown Button Functions Once and Then Stops

I am facing a challenge in implementing a button within an HTML table that triggers a dropdown menu when clicked, and closes upon another click or when the user clicks outside the menu. Oddly, the button only seems to work once before completely losing fun ...