Employing ng-style for establishing background when the value does not align

Greetings all! I am using ng-repeat to create a list of items within a ul element.

Within the json data, there is a specific value that I want to highlight if it does not match a predefined string. Here's what I have so far:

ng-style="{'background-color':(json.string !== 'NO_MATCH' ? 'yellow')}

Below is the complete code for the ng-repeat section:

<li ng-repeat="json in json" ng-style="{'background-color': (json.string !== 'NO_MATCH' ? 'yellow')}>{{ json.title }} - {{ json.display }}</li>

I seem to be encountering an issue with this setup. Can anyone help me figure out where I might be making a mistake?

Answer №1

Instead of using ngStyle, it is recommended to use ngClass. This is because ngStyle adds inline styles to the element.

Here's an example in CSS:

.yellow {
  background-color: yellow;
}

And here's how you can use it in HTML:

<li ng-repeat="json in json" ng-class="{'yellow': json.string !== 'NO_MATCH'}">{{ json.title }} - {{ json.display }}</li>

Answer №2

Give this a shot?

ng-style="{'background-color: yellow;': json.string!=='NO_MATCH'}"

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

To enhance user experience, it is recommended to reload the page once

Hello, I'm looking for a way to automatically refresh the page after submitting an AJAX form. Currently, I have an onClick function that seems to refresh the page, but I still need to press F5 to see the changes I've made. Here's the JavaSc ...

I am interested in utilizing Google Apps Script (GAS) to store images in GoogleDrive and automatically populate the corresponding URL in a

Currently, I am utilizing GoogleAppsScript to develop a form for submitting names and images. The idea is to store the submitted name and image in GoogleSpreadSheet while also storing the image in GoogleDrive along with its destination URL. The process inv ...

React js code to create a position ranking table

Currently, I am in the process of developing a web application using Reactjs with a ranking table managed by Firebase. However, I have encountered a question: Is it possible to dynamically change the position numbers after sorting the table based on the am ...

Changing the default view in Ionic

I'm facing a simple issue that I can't seem to solve. I've set up a blank project in Ionic and I want to make a default home screen the first view that loads. However, all I see is a blank screen when I run it in the browser. Here's my ...

Ways to establish a specific minimum width for a container and disregard small breakpoints in Bootstrap 5

I want to set a fixed minimum width for a container while ignoring small sizes like sm and xs. Basically, when the screen size is less than 960px, I want the width to be fixed and only display a scroll. This is the code I have: <div class="contain ...

In Python, extract data from the top level of a JSON file

Looking for assistance with parsing a JSON stored as a string: message = """{"info":{"keyVersion":1,"timestamp":"2020-11-05 20:00:00","encryptedData":"75657374696f6e732068617665207265636 ...

"Enhancing Your Website with Dynamic CSS3 Div Animations

Seeking assistance in displaying an empty div after a CSS3 Animations loading circle has completed. Any guidance is welcome! jsFiddle ...

Adjust the angle of an object precisely using a transform upon hovering over a designated button

I am looking to design a menu that always keeps the arrow pointing at the button I hover over with my cursor. If I don't hover on any button, then it should stay in the position of the last button I hovered over. HTML: <html lang="en"> <hea ...

Determining the exact position of an image with resizeMode set to 'contain' in React Native

I am currently developing an object detection app using React Native. The process involves sending an image to the Google Vision API, which then returns a JSON file containing coordinates and sizes of objects detected within the image. My goal is to draw r ...

jQuery Ajax fails to serialize the input type file field

Here is the Razor code snippet that I use to return a form to a jQuery function upon submission: @model Slider @{ Layout = null; } @using (Html.BeginForm("AddOrEdit", "Slider", FormMethod.Post, new { enctype = "multipart/form-data" ...

Two conflicting jQuery plugins are causing issues

In my journey to learn jQuery, I encountered an issue while working on a website that utilizes a scroll function for navigating between pages. The scripts used in this functionality are as follows: <script type="text/javascript" src="js/jquery-1.3.1.mi ...

Is it feasible to link an Angular property value to the value of an HTML data attribute?

Can an Angular property value be bound to a data attribute on a template element? <h1 data-name="{{name}}">Hello from {{ name }}!</h1> Example Link After running the code, it results in the following error: Error in src/main.ts (11: ...

How to include a new variable within a JSON string using C#

I have been working on some code to make it more dynamic. Originally, I used a hardcoded ID in my json string to post a new object with NUnit Test Project using RestSharp. Now, I am attempting to remove the hardcoded object ID and replace it with an empt ...

Managing ng-show in AngularJS outside the ng-repeat loop

Currently, I am diving into the world of Angular and experimenting with toggling the visibility of content div based on clicks on side menu items. <div id="side-menu"> <h3>Side Menu</h3> <div ng-repeat="item in example"> &l ...

Error: Unforeseen JSON reply from node

I am a beginner in programming and if my question is unclear, please let me know. I will try to simplify it. Recently, I made a request to a Restful API, using this code snippet const request = require('request'); var myJSONObject = { "call":"L ...

Retrieve unique JSON formats for the identical object

Is it possible to customize the serialization process of a Java object into a JSON string using Jackson in order to generate various JSON outputs from the same object? For example, a compressed JSON output could look like this: { "a":"123", "s":"100" ...

Can someone help me identify the issue with my JavaScript code?

Recently, I attempted to transfer data from JavaScript to HTML using Angular. Here is the code snippet: phonecatControllers.controller('start', ['$scope', function($scope){ $scope.lloadd=true; console.log('data - '+$ ...

Revitalizing and rerouting page upon button click

The issue at hand is: When the "Post now" button is clicked, the modal with the filled form still appears. If the button is clicked again, it adds the same data repeatedly. I aim to have the page refresh and navigate to a link containing the prediction d ...

Modify CSS using JavaScript at a specific screen size

Currently, I am in the process of designing a responsive navigation system which involves implementing a button that dynamically changes the styling of the div #navigation using Javascript. The aim is to toggle between display: none; and display: block; ba ...

Unending React cycles - invoking setState() within a render onClick

Recently delving into React and facing an issue with rendering a button component. My goal is to create a button that, upon being clicked, fetches data and displays it as a list below the button. To achieve this, I am attempting conditional rendering. I ut ...