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

Having trouble aligning and resizing text and divs accurately

Hello, I'm having trouble centering my text within a div and fitting three divs inside my content area. Here is the code snippet: HTML <div id="content"> <div class="latest"> <p>Gentlemen, these are my latest works< ...

Using AngularDart: Maximizing Efficiency with Dual ng-repeat Expressions in a Single Tag

I am looking to create a grouped table that resembles the following structure: Customer Site ------------------------------ Customer 1 Site 1.1 Site 1.2 Site 1.3 Customer ...

Using CSS to break or wrap long words in text

I have a div that spans the width of the page. I'm looking to ensure that a very long word in this div breaks and wraps properly, so all the content stays within the screen width and doesn't overflow beyond 100%. Although I've attempted usi ...

Executing controller method through a preflight OPTIONS call for Web API CORS functionality

My angular app is making calls to a WebApi with authentication and sessions enabled, requiring preflight calls for GET and POST methods. I have implemented Cors in the WebApiConfig.vb file. Public Sub Register(config As HttpConfiguration) Dim corsAttr ...

The scrollbar fails to reach the bottom of my table, preventing me from viewing the entire content

I'm currently facing a challenge with a table on my webpage that displays data but isn't scrolling all the way to the bottom. This code was implemented by previous developers, and as someone who isn't well-versed in CSS, I'm struggling ...

Error: Request Timed Out - The asynchronous callback function was not executed within the specified timeout set by the jasmine.DEFAULT_TIMEOUT

Currently, I am in the process of testing my Ionic app using Jasmine. Below is a snippet from my test suite: beforeEach(() => { auth = new Authentication(<any>new HttpMock(), <any>new StorageMock()) user = new MockUser(); head ...

The MIME type 'text/html' is incompatible with stylesheet MIME type and is not supported

I have exhausted all possible solutions for the issue, from specifying the type for <link rel="stylesheet" href="./style.css" /> to using app.use(express.static('public')), but unfortunately, none of them seem to resolve the problem. index ...

Refresh an image on my webpage using jQuery

There seems to be an issue on my page where one of the images only displays after reloading the page. Initially, the image only loads partially. The reason behind this behavior is still unclear to me. I've been attempting to reload only the image on ...

Align text to the left of a button with Bootstrap 4

Currently, I have two buttons stacked on top of each other. I'm attempting to include some text to the left of the bottom button, but I am encountering two obstacles: The first issue is that it creates a white round-ish shape around my top button w ...

What is causing all three boxes to shift when I'm attempting to move just one of them?

Seeking assistance with a problem I'm encountering. As I work on creating my website, I've run into an issue where trying to move one of the three individual boxes (as shown in the image) causes all three of them to shift together. You can view t ...

Step-by-step guide on utilizing User scripts with the $window.open function in AngularJS

I am looking to initiate the following action - (for example: Upon clicking a button, it should direct to this , similar to how payment gateways function) and then, I need to input the user script below: getRealData('{"mailing":{"postalCode":"1 ...

Ensure that a span within a cell table has a height of 100%

Is there a way to have the span element expand to full height? Click here <table class="table table-condensed table-hover table-striped"> <thead> <tr> <th class="shrink"></th> <th class ...

Achieve a responsive layout by dynamically sizing child div elements to fill their parent container using percentage-based margins and

I'm having trouble getting the child divs to stretch to the parent, and I'm not sure if I need to specify a % width on #fullpage-content even though #middle is set to 76%. I seem to have forgotten... Would you like to check out this link where c ...

How to achieve a reverse slideToggle effect with jQuery when refreshing the page

After creating a custom menu on Wordpress using jQuery slideToggle to toggle dropdown on hover, everything seemed to be working perfectly. However, I noticed that when I refreshed the page while moving my cursor between two menu items with dropdown menus, ...

How do I resolve the issue of a non-iterable 'int' object?

1 How can I troubleshoot the error that is popping up? I believe the issue may be related to it being a dictionary. Any suggestions on how to fix this problem? views search(request): if "q" in request.GET: querystring = request.GET.get(" ...

The $scope within the $ionicplatform is not functioning as expected

I've been working on an application, but it doesn't seem to be functioning correctly. Typically, when we add a value to the scope, I expect it to update in the application. Here is the snippet from index.html: <body ng-app="starter"> <i ...

"Customize the dimensions and scroll behavior of a division

I've been struggling to make a single-page site full-width, and I can't seem to get it right. My goal is to create sections that are: Full width Background image full width The height of the div should be at least the same as the image, adjust ...

Tips for concealing links in ui-grid post-click with AngularJS

When using Angular-UI-Grid, I am working with the following paginated data: Name | Link A | Show Hide B | Show Hide Within my options: cellTemplate:'<div>' + ' <a ng-click="grid.appScope.show(row)">Show</a> ...

The header appears distorted on older versions of Internet Explorer, specifically IE 7 and IE

The website I am currently working on looks great in Chrome, Firefox, Opera, and Safari on both Mac and Windows. However, it is not displaying correctly in IE 7 & 8. The header should appear like this: But in Internet Explorer, it's showing up like t ...

Using Rails Devise as a backend to validate users in an Ionic application

Is anyone experienced with setting up authentication for an Ionic app connected to a Rails API using Devise? If so, I'd love to hear about your implementation and any helpful tutorials you've used. Please share your insights. ...