Adjust the appearance of a glyphicon by modifying its color according to various criteria

Using angularjs, I implemented ng-repeat to display details in a table. In the final column, I aim to display the glyphicon 'glyphicon glyphicon-stop' in a specific color.

<tr ng-repeat="ps in $ctrl.personLst">
<td>{{ ps.id}}</td>
<td>{{ ps.birthday | date: 'dd.MM.yyyy'}}</td>
<td>{{ ps.age }}</td>
<td>{{ ps.country }}</td>
<td>{{ ps.continent }}</td>
<td> //TODO <td>

.color-green {
  color: green;
}

.color-blue {
  color: yellow;
}

.color-red {
  color: red;
}
  • RED
    • Age over 30, Country 'GER', and Continent 1
  • BLUE
    • Age under 30, Country 'RS', and Continent 1
  • GREEN
    • Age under 10, Country 'TS', and Continent 3

Is it possible to achieve this? Here is my latest attempt:

<td><span class="glyphicon glyphicon-stop" ng-class="{'color-red': ps.age > 30 && ps.country === 'GER' && ps.continent === 1}" ></span></td>

Answer №1

To organize this logic more effectively, you can create a separate function within the controller:

$scope.setClass(person){
   if (person.age > 30 && person.country === 'USA' && person.continent === 2){
     return 'color-blue';
   } 
}

Then in the HTML view, you would use:

<td><span class="glyphicon glyphicon-heart" ng-class="setClass(person)" ></span></td>

Answer №2

Don't forget to add a closing } at the end of your ng-class attribute. It should look like this:

ng-class="{'highlighted': item.isActive }

For further details, check out:

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

Developing a web application using Yeoman generator to scaffold an AngularJS frontend with an Express server

I am currently experimenting with using ExpressJS alongside the pre-built version of Angular provided by the Yeoman generator for AngularJS. I have opted to utilize the scaffolding created by the Yeoman Team rather than relying on frameworks like angular-f ...

Display or conceal div elements using JavaScript

Is there a way to hide certain divs when clicking on a specific div box? Clicking on the box will trigger the hiding of some application divs. See the first image below: When the boxes are hidden, the other divs will readjust in place of the current divs ...

"Enhanced interactivity: Hover effects and selection states on an image map

Hello there, I need assistance with my code. Here it is: <img id="body_image" usemap="#body_map" src="assets/images/body.jpg" alt=""> <map name="body_map"> <area shape="poly" alt="d" href="#body_chart" name="ad" coords="153, 153, 145, 1 ...

The content inside the inner div does not stretch to match the height of its parent element

I want to address a specific issue I am facing with my div structure. Although it may seem similar to other questions on StackOverflow, none of the existing solutions have worked for me. The problem is that I have two child divs inside a parent div. The h ...

Using the scroll feature within the tooltip component in React with @material-ui/core/Tooltip can cause the entire page to

I am currently working with a tooltip created using the @material-ui/core/Tooltip library, and it is functioning correctly. You can see an example of the tooltip in action at this link: https://codesandbox.io/s/kgccc. https://i.stack.imgur.com/fMgGb.png ...

Choose a specific date on a Materialize datepicker and set it as the selected date

I am currently developing an application using Materialize that includes two datepickers: $(document).ready(function(){ $('#outDate').datepicker({ format: 'dd-mm-yyyy' }); }); $(document).ready(function(){ $(&apos ...

The CSS infinite animation becomes erratic and sluggish after a short period of time

My website featured a banner with a series of thumbnail images that animated at different intervals and looped indefinitely. Initially, the animations ran smoothly, but after a few seconds, they began to slow down and lose consistency. To troubleshoot, I u ...

JavaScript and HTTP Post parameters: Consider using optional additional parameters

Managing a filtration function, I have an array of checkboxes and dropdowns. Users can select multiple checkboxes and dropdown values before clicking on the "Filter Now" button. Upon clicking the button, a POST request is triggered to my API, passing alon ...

Having trouble with Viewport CSS being restricted by Blogger?

I've been working on configuring my personal blog, which is hosted on Blogger, to properly adapt to the Windows 8 IE snap feature. Through my research online, it has been suggested that I include a @viewport in the CSS. However, it seems like the CSS ...

Troubleshooting problem with scrollbar in HTML table within a div element

I'm utilizing Bootstrap for the majority of my CSS. I've split a section into two columns, with the left column displaying a table with data and the right side featuring a Google map. The issue arises when the table row grows, as it doesn't ...

Is the value incorrect when using angular's ng-repeat?

Currently iterating through an array nested within an array of objects like this: <div ng-repeat="benefit in oe.oeBenefits"> <div class="oeInfo" style="clear: both;"> <div class="col-md-2 oeCol"> <img style="he ...

Loading content from external sources on the dashboard

I'm trying to figure out how to load an external URL () within the content of a Dashboard. My current code looks like this: .state('app.urlloading', { url: '/url-loading', controller:function($window){ $window.locat ...

Using Selenium to locate and click on a hyperlink within a table by identifying it with its displayed name

In my case, I have a table that displays records of school districts. My goal is to use Selenium in order to select the delete icon positioned in the eighth td for the district located on a row with a specific name. In this scenario, the name being QA__run ...

What is the reasoning behind placing the CSS file in the header section and the JS file at the bottom

Hey there, I need some help. Why is the CSS file included in the header section but the JS file at the end of the page? Can I also include the CSS file at the bottom of the page? <!DOCTYPE html> <html> <head> <link type= ...

Navigate to a different HTML file following a JavaScript function in Ionic and AngularJS with Cordova

I am currently creating an Android application in Cordova Tools for Visual Studio using Ionic and AngularJS. My goal is to redirect to another HTML page once my function has completed its execution, but I'm having trouble getting it to work correctly ...

Hacking the power of combining Bootstrap 3 with AngularJS to create a unique

Recently, I came across this HTML code snippet that got me thinking: <div class="input-group"> <input type="number" class="form-control" name="distance" ng-model="calculatorData.distance" placeholder="Distancia" required> ...

Steps to obtain the precise source code of a webpage

Is there a way to download the exact source code of a webpage? I have tried using the URL method and Jsoup method, but I am not getting the precise data as seen in the actual source code. For example: <input type="image" name="ctl00$dtlAlbums$ct ...

Step-by-step tutorial on designing an input slider to dynamically adjust the CSS :before linear-gradient values

Is there a way to achieve a gradient effect using pseudo-element :before on an image that can be customized by adjusting a slider input? I've been trying to implement this feature with the following code, but have not been successful so far. var ...

Unexpected behavior observed with field alignment

I've been attempting to align the field in an Angular HTML page, but it's not working out as I expected. Here's how the HTML file looks: <div id="report-prj-search"> <div class="dx-fieldset flex-column"> <div class="fle ...

Issue observed with alignment not being corrected when the browser is resized on a responsive webpage

Utilizing Bootstrap3 for my responsive page design. In the banner content, I am including a box with text inside: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> <div class="row"> <s ...