If the value of one of my keys is Green/Red, I would like to display a bootstrap button with the class btn-success
when its value is green and btn-danger
when it's red.
If the value of one of my keys is Green/Red, I would like to display a bootstrap button with the class btn-success
when its value is green and btn-danger
when it's red.
Your ng-class
attribute needs to be updated:
<div ng:controller="CartForm">
<ul>
<li ng-repeat='country in countries'><a class="btn" ng-class="{'btn-primary': country.color == 'green', 'btn-danger': country.color == 'red'}" href="">{{country.name}} - {{country.population}}</a></li>
</ul>
</div>
In addition, the appliedClass
function should be deleted.
View a working example on jsFiddle
Have you considered using ng-class? You can implement it like this:
<p ng-class="condition ? 'classIfTrue' : 'classIfFalse'">Foo</p>
In your scenario, it could look something like this:
<p ng-class="myVariable ? 'btn-success' : 'btn-danger'">Foo</p>
If you need a code example to understand how it functions, take a look at this one:
angular.module('app', []).controller('MyCtrl', function() {
this.valueSuccess = false;
this.valueDanger = true;
});
.danger { background-color: red; }
.success { background-color: green; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<section ng-app="app">
<div ng-controller="MyCtrl as vm">
<p ng-class="vm.valueSuccess ? 'danger' : 'success'"> {{vm.valueSuccess}}</p>
<p ng-class="vm.valueDanger ? 'danger' : 'success'">{{vm.valueDanger}}</p>
</div>
</section>
Hey there, I've been working on a simple AngularJS application and running into some trouble with Protractor in Chrome. Here's a snippet of my code: HTML: <div> <div> <ul...... <li.........../li> <li............./li> ...
I am currently testing an AngularJS application and I am relatively new to using protractor. Whenever I open the browser, it opens successfully but then waits for a timeout before displaying the following error in the command prompt. Protractor synchron ...
I want to ensure that my JSON API response is easily organized into a class or interface so that I can always identify the attributes present. The JSON data I am working with is as follows: { "users": [ { "id": "bd3d70fd-03f7-4f5e-9ac1-4cb7221 ...
As I navigate through the research debate between relational databases and NoSQL, I have decided to move forward with PG as my data store. The introduction of JSONB in version 9.4 played a significant role in this decision. Now that I want to implement jso ...
I am encountering an issue where only the last JSON request is being saved to a file, which I suspect is causing my general.json file to be overwritten each time. My goal is to append all requests to general.json. Can someone please help identify the probl ...
I am currently working on a PHP page that retrieves data from MySQL. The goal is to fetch a list of objects from the database, display each object in a separate form for editing, and then save only the edited values. However, I am encountering difficulties ...
Perhaps I am posing this question again, but this is my first attempt and I haven't come across anything quite like my situation.. As I code in C# and utilize JSON.NET to deserialize a JSON, the JSON file is retrieved from Twitter as a response to ...
Is there a way to ensure that the canvas in this demonstration remains centered at all times, even when scrollbars appear and the window is resized? The goal is for the canvas element to always fill the window. Despite my attempts to adjust settings like ...
Take a look at this page comparison between chrome and IE. On the right side, you'll notice drop down fields. While Chrome displays them correctly, IE shows rectangular boxes instead. To fix this issue, I added opacity to the select fields with the ...
I need help with creating a popover that appears when hovering over an anchor tag. Here is the code I am using: angular: 1.4.2 ui-bootstrap :0.14.2 <div class="row" ng-repeat="endorsement in endorsements| filter: {category:categorySelected}"> &l ...
I have created a custom directive using AngularJS 1.4.3. Below is the code for my directive: 'use strict'; angular.module('psFramework').directive('psFramework', function () { return { transclude: true, s ...
Whenever I try to extract data from JSON, I always encounter the error TypeError: unhashable type: 'dict' Here is my JSON information: u 'paging': { u 'cursors': { u 'after': u 'MTQyNzMzMjE3MDgxNzU ...
Can the background color of an HTML meter be customized? I noticed that by default, it has a green background. Is there a way to change this green background to a different color? I attempted using the style attribute with a red background color, but it ...
Trying to create three image links that display different divs when onMouseOver. <script type="text/javascript> function toggleVisibility(divid) { if (divid==="1"){ document.getElementById("1b").style.visibility = "visible"; document.getElem ...
Is there a way to center align the text in this image with minimal use of CSS/HTML? The icons on the left are causing it to be off center: https://i.sstatic.net/TKOYG.png Below is the relevant HTML and CSS for this top section: <div class="navbarhead ...
After successfully constructing a SQL query that incorporates three conditions from my database table and sets a flag based on them, I have made progress in my project. The query looks like this: UPDATE staging SET `miuFlag` =1 WHERE `lowSideMIUNumAr ...
Having trouble with this HTML element : <span class="item-menu-notif non-lue" onclick="dosomething(2150)"> TEXT </span> These are the CSS classes : .item-menu-notif{ display: block; cursor: pointer; padding: 0 0.4em 0 0.4em; } s ...
I encountered the following error: SyntaxError: missing ; before statement Although I am unsure of what is causing this error, here is the code snippet that I am currently working with: (function pollschedule(){ $.ajax({type: "GET", dataType: "j ...
Within my code, I have stored a JSON response in a variable named savedData = {"ID":"{{ID}}","command":"ok"}. Additionally, I have created an array variable called ID = [1,2,3]. My goal is to iterate through the JSON based on the array variable and utilize ...
Having trouble with a button wrapped inside a custom Navbar component. The code snippet in question is: <NavBtn> <Link href="/contact" passHref> <Button> Contact Me </Button> </Link> & ...