The ng-class styling isn't being implemented

I am facing an issue with updating the text color inside a div tag based on values from an array within an ng-repeat. While the value is correctly set during debugging, the color does not display properly.

<div ng-class="sel.fav == 'Y' ? 'fz-horse-name-green' : 'fz-horse-name'">{{sel.sel_name}} : {{sel.fav}}</div>

The CSS classes I am using are:

.fz-horse-name-green{
    display: table-cell;
    width: 40%;
    text-align: left;
    font-family: 'Oswald', sans-serif !important;
    font-size: 220%;
    font-size: 2.2vw;
    color: limegreen !important;
    padding-left: 2%;
}
.fz-horse-name{
    display: table-cell;
    width: 40%;
    text-align: left;
    font-family: 'Oswald', sans-serif;
    font-size: 220%;
    font-size: 2.2vw;
    color: white;
    padding-left: 2%;
}

I have verified that the value I am checking inside the class is

sel.fav correctly prints "Y" within the same div, however, the CSS color does not appear even though I added "!important".

When inspecting the HTML snippet in Chrome developer mode, it shows as follows:

<div ng-class="sel.fav == 'Y' ? 'fz-horse-name-green' : 'fz-horse-name'" class="ng-binding fz-horse-name-green">TOYNEBEE : Y</div>

This indicates that the correct class is being applied, so what could be causing the issue of not applying my CSS / not changing the text color correctly based on the condition?

I have provided a sample fiddle where it works fine. I am puzzled why it is not working in the actual scenario?

http://plnkr.co/edit/XhaxncmzzNFXmZryKkyr?p=preview

Answer №1

Make sure that all items have the fz-horse-name class included

.fz-horse-name{
    display: table-cell;
    width: 40%;
    text-align: left;
    font-family: 'Oswald', sans-serif;
    font-size: 220%;
    font-size: 2.2vw;
    color: white;
    padding-left: 2%;
}

The fav class serves to enhance the existing appearance of the element

.fz-horse-name.fav{
    color: limegreen;
}

You should apply the fav class based on a certain condition

<div class="fz-horse-name" ng-class="{'fav': (sel.fav == 'Y')}">
  {{sel.sel_name}} : {{sel.fav}}
</div>

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

What is the best way to implement a dynamic form within a fieldset using jQuery Mobile?

I am trying to dynamically insert a form inside a fieldset. This is my approach using jQuery: $(document).on("pagebeforeshow", "#mainPage", function () { if (sessionStorage.login_state != 1) { alert('You don&bsol ...

Customizing the font color and size of the brand text in the Bootstrap 5.1.3 Navigation Bar is not allowed

I am currently working on a main page that includes a bootstrap navigation bar with a dropdown menu. I have successfully managed to display the dropdown menu and change its color using CSS. However, I encountered an issue when attempting to modify the font ...

ui-router: Issues with utilizing the <ui-view> element within a bespoke directive

In my current project, I am utilizing version 0.3.1 of ui-router. Within my custom directive, there is a <ui-view></ui-view> tag present. <div > <button type="button" class="btn btn-primary btn-circle btn-lg pull-left" ui-sref="u ...

Troubleshooting a Label Overlapping Problem in Materialize CSS

I've been working on a Materialize project and encountering an issue with pre-filled values in text boxes. Here is a snapshot of the problem: https://i.stack.imgur.com/u13jT.png <div class="input-field col s12 m6"> <input class="" id="us ...

Ways to align elements vertically in a container without using flexbox?

I am working with a ul element that has a height of 270px and contains 10 li elements. My goal is to have all the li elements vertically justified, meaning the top and bottom li elements should touch the container's top and bottom respectively, while ...

Show product name when hovering over the image

Trying to achieve a hover effect where product titles appear in a contained box when hovering over the product image on the bottom overlay, instead of below the image itself. Tried CSS code recommended by Shopify, but it had no effect: <noscript> ...

AngularJS - sorting JSON data based on key values

I am working with a JSON data set that I need to filter based on the selected option value. The select input is bound to an ng-model, but for some reason, the filter isn't functioning properly. Can anyone spot what mistake I might be making? This is ...

Learn how to make a contenteditable div perform tab spacing with a simple keystroke of the tab key

I've been trying to figure out how to make this contenteditable div add tab spacing when I press the tab key, but so far no luck. If anyone has a solution for this issue, please feel free to share. You can use an ID, class, or any other method to get ...

Activating Bootstrap modal when a navigation link is clicked

Just started a site for a client and new to Bootstrap. I've got the layout down - full-width page with "Top Nav" within the nav bar, looking to create a modal effect drop-down. When clicking on "About", it should trigger the .modal function. However, ...

Is it possible to exclude elements that are not something or something else using :not()?

Let the example do the talking .cyan { background-color: cyan; } .red { background-color: red; } .green { background-color: green; } .blue { background-color: blue; } .yellow { background-color: yellow; } li:not(.yellow), li:not(.green) { c ...

AngularJS is unable to return a value when using $resource

I may be new to AngularJS with only 20 hours of experience, but I've been assigned the role of a backend developer in Java. The backend is definitely returning data, but for some reason, the function below is not retrieving it. Can someone please assi ...

What is the best way to implement anchor links within elements located within md-content?

After transitioning to Angular material for a project, I encountered an issue with the navbar (now a toolbar) buttons that were meant to scroll to different sections on the page. To achieve the desired toolbar shrink effect and reappear on scroll up, I ha ...

Using CSS to resize an element with both dimensions while maintaining its

Is it feasible to preserve a 1:1 aspect ratio on a div element using the CSS resize property? This particular illustration lacks an aspect ratio. Do you have any recommendations? ...

Scrolling issue with overflowing content in Bootstrap 4 tabs

Currently tackling a Bootstrap 4 Holy Grail layout. My goal is to make each column scroll overflowing content independently without specifying a height. The left column works fine, but the right column contains a Bootstrap NAV/TAB widget. Specifically, th ...

JavaScript Issue: Unable to Update or Delete Table Row Data

Presently, I am involved in developing a project titled : Tennis Club Management using a blend of Javascript, HTML, CSS, and Bootstrap. This project encompasses several HTML pages and a JS file such as index.html, profile.html, manageFees.html, index.js, e ...

AngularJS - my custom directive link function is not being executed

I'm encountering an issue where my directive link is not being called in my Angular app. Can anyone provide assistance? Here is my directive: <data-grid data=slideView.pages ></data-grid> Below is my code: "use strict"; ( function() { ...

Error: Attempting to access 'position' property of undefined object in ThreeJs is causing a TypeError

I am currently facing an issue with integrating a 3D model into the background of the hero section on my website. The integration works fine, but I noticed that when I manually resize the window, the 3D model does not adjust to the new size. Additionally, ...

Is there a way to hide the blinking cursor at the conclusion of the animation after 3 seconds?

I've been working on this HTML snippet <div class=typewriter> <h1>Lorem Ipsum</h1> </div> and included some CSS styles as well .typewriter { display: inline-block; } .typewriter h1 { overflow: hidd ...

Fully compatible with Internet Explorer 6, with a height of

Is there a way to create a div that is always 100% the height of the browser, even if it's empty, and works in IE6? Any suggestions or hacks using CSS? ...

Tips on creating CSS for an element with certain text within it?

I have a text element List that I need to select. Instead of using xpath like - //li[text()='List'] I want to use css. How can I write css for this? I attempted the following after referring to but it didn't work. li:contains('List& ...