style the table cells based on results of winner values retrieved from JSON

After fetching JSON data, I am utilizing angular JS to present it in a table.

The table consists of multiple rows that are populated from the JSON file using ng-repeat.

The value for Status.winner can either be 0 or 1.

If the winner's value for a particular row is 0, I want to emphasize Playerdata[0].playername for that row by highlighting it in yellow.

Conversely, if the winner's value for the row is 1, then I intend to highlight Playerdata[1].playername in yellow color for that specific row.

I need assistance in achieving this highlighting effect for each row with varying winner values of 0 and 1.

<body ng-app="form-input" ng-controller="ctrl">
<table class="table table-bordered table-condensed ">
  <caption>Recent Game Statistic</caption>
  <tbody> 
  <tr class="success"  ng-repeat="status in recentGame">      
    <td ng-bind="status.Winner"> </td> 
    <td ng-bind="status.Playerdata[0].Playername"> </td> 
    <td ng-bind="status.Playerdata[1].Playername"> </td> 
  </tr>  

var app2 = angular.module('form-input', []);

app2.controller('ctrl', function($scope,$http) { 

var url = "http://...JSON";

$http.get(url).success( function(data) { 
  $scope.recentGame = data.RecentGames; 
  });   
})

Answer №1

Implement ngClass in your code:

<tr class="success" ng-repeat="status in recentGame">      
    <td ng-bind="status.Winner"></td> 
    <td ng-bind="status.Playerdata[0].Playername" ng-class="{winner: status.Winner == 0}"></td> 
    <td ng-bind="status.Playerdata[1].Playername" ng-class="{winner: status.Winner == 1}"></td> 
</tr>

To style the .winner class, you can define it in your CSS file like this:

.winner {
    background-color: yellow;
}

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 AngularJS ng-if directive is failing to function properly, despite the logged boolean accurately reflecting the

I created a custom directive that handles the visibility of text elements on a webpage. While this logic works correctly half of the time, it fails the other half of the time. Here is the code snippet from my directive: newco.directive 'heroHeadline& ...

Are max-width:auto and max-width:100% the same thing?

Does max-width set to auto have the same result as setting max-width to 100% If not, what is the distinction between them? ...

Unable to parse JSON data for grid display due to stream decoding issue: java.io.FileNotFoundException

My goal is to showcase images from a path stored in a remote MySQL database on an Android application within a GridView. However, I am struggling with the implementation and would greatly appreciate any guidance. Below is the code snippet where I fetch th ...

Tips for assigning a class to a div based on the route in Angular

In my angular template, I have a basic ng-repeat with some div elements. Now, I am looking to add a class to a specific div if the $routeParams.userId matches the id of the object in the loop. You can refer to the second line of code below for clarificatio ...

Display a specific template in the detail grid of the Kendo Grid depending on certain conditions

I've been using the Kendo Grid and it's been working well for me. I have a requirement to check each row in my grid to see if it contains a specific value, and based on that, bind data using different templates. Is this feasible? Below is the cod ...

Opacity in text shadow effect using CSS

Within my text lies the following css snippet: .text-description-header { font-size: 250%; color: white; text-shadow: 0 1px 0 black; } Observe the dark shadow effect it possesses. Inquiry I am curious if there is a way to alter the shadow t ...

Filtering in JavaScript can be efficiently done by checking for multiple values and only including them if they are not

In my current coding challenge, I am attempting to create a filter that considers multiple values and only acts on them if they are not empty. Take the following example: jobsTracked = [ { "company": "Company1", ...

Retrieving the JSON value from a data attribute and then locating the corresponding JSON key in a designated element within the DOM

I have an HTML element that contains a data attribute: <a href="#" data-trigger="{ "rem": "albatros", "ap":1 }'">Remove</a> <div data-container> <p>lorem ipsum<p> <p data-rem></p> </div> 1. So ...

There seems to be an issue with the functionality of the Bootstrap Modal

I've been working on incorporating bootstrap login Modal functionality into my code, but for some reason, the screen is not displaying it. Here's what shows up on the screen: The red box in the image indicates where I am expecting my Login Modal ...

Tips for including HTML in a JSON request in ReactJS

Upon sending the request as shown below, the response was successfully received. { "contractId": "siva8978", "html": "<p>PREFERENCE SHAREHOLDER AGREEMENTTHIS AGREEMENT is made on the&nbsp;$$Contract Start Date$$ BETWEEN&nbsp;CRADLE WEALTH ...

Positioning the navigation buttons along the edges

I'm struggling with creating a custom slider and am having trouble placing the navigation buttons on the sides. You can view the current layout on JSfiddle: http://jsfiddle.net/zfxrxzLg/1/ Currently, the navigation buttons are located underneath the ...

Locate XML attribute in VS code and substitute it with the product of the current value and a

Editing a massive XML file with numerous contents can be quite time-consuming. Is there a feature available in editors like VS Code that allows users to specify a field and then multiply it by a certain value? This would significantly speed up the editin ...

Protractor encountering difficulties using by.repeater() on ng-repeat element

I am currently facing an issue with my Angular HTML code while attempting to conduct end-to-end testing using protractor for clicking on a dropdown. Below is the snippet of the HTML code: <ul class="dropdown-menu"> <li ng-repeat="currency in ...

One of the paragraphs refuses to align with the others by floating left

Greetings everyone! This is my first time posting here, although I have been a regular visitor looking for answers on this site. Hopefully, someone can assist me with my current issue. Let me explain my problem: I've been attempting to align all the ...

Unrecognized Characters in PDF JavaScript Blob

I am facing an issue with serving a PDF file from a WebApi 2 application to an AngularJS client. I use file-saver library for saving the file on the client side in TypeScript: this.$http.get(`${webUrl}api/pdf?id=${fileDto.id}`) .then((response: ng.IHt ...

Returning to the initial state after clicking on an element within a repeated set in AngularJS?

I'm currently facing a challenge, mainly due to my lack of understanding in basic AngularJs concepts. The issue arises when I interact with a list of clickable words. When I click on any of these words, their color changes individually thanks to the i ...

My custom styles no longer seem to be applying after upgrading Angular Material from version 14 to 15. What could be causing this issue

Having some challenges with the migration from Angular 14 to Angular 15 when it comes to overriding material UI elements and themes. Looking for blog posts or documentation that can provide guidance on how to smoothly transition. Specifically, experiencin ...

Can the hexadecimal code for a particular color name be identified?

Similar Question: Javascript function to convert color names to hex codes Is there a way to determine the hexadecimal value of a named color that is currently being used by the browser? For example, I would like to achieve something similar ...

Numerous lists conveniently consolidated within a single navigation bar

I am currently exploring the functionality of StumbleUpon's navigation bar by attempting to replicate it. My approach involves using 3 lists within 1, structured like this: <nav role="navigation"> <ul id="rightnav"> & ...

Angular/JS encountered a premature end of program unexpectedly

I am taking my first steps in the world of web development with Angular (and JavaScript in general). I have been trying to rewrite some basic and common examples using Angular. One thing I attempted was to display a simple message using data binding. This ...