Unable to show the table row color using Angular in Internet Explorer

I've customized a table by changing the row color based on a property value, and I'm using ng-repeat to display the rows. Here's my table:

<table class="tab table span6 tabhover" style="margin:0;" >
            <thead>
                <th>No. Parte</th>
                <th>Cantidad</th>
                <th>Descripcion</th>
                <th>Estatus</th>
                <th>Fecha estatus</th>
            </thead>
            <tbody ng-repeat="r in reqs">
               <tr ng-class="{selected: r.idrdm_detalles == idSelectedVote}"   ng-click='detallesHistory(r.idrdm_detalles)'    bgcolor="{{r.color}}"> 
                <td>{{r.numeroparte}}</td>
                <td>{{r.cantidad}}</td>
                <td>{{r.descripcion}}</td>
                <td>{{r.estatus}}</td>
                <td>{{r.fecha_estatus}}</td>
               </tr> 
            </tbody>
        </table>

The background color of each row is determined by the "color" property of the object.

For setting the row color, I've implemented this function:

this.color = function(codigo){
            if(codigo == 10){
                return '#00A6E8';
            }
            else if(codigo == 60 || codigo == 80){
                return '#51BD53';
            }
            else if(codigo == 90 || codigo == 99){
                return '#DE5F5F';
            }
            else{
                return '#F5AB2C';
            };
        };

In my controller, I use Angular forEach to add the color property to each data array entry:

angular.forEach(data, function(value, key){
                    var c = value.codigo;
                    value.color = self.color(c);

                    $scope.idrdm = req; 
                    //console.log(value);
                });
                $scope.reqs = data;

The row background colors are displayed correctly in browsers like Chrome, Firefox, and Safari. However, in Internet Explorer, the color appears as "#00c00" instead of the expected color. If anyone has insight on how to address this issue, please let me know. PS. I tried using ng-style like this:

<tr ng-style="'{background-color':{{r.color}}"> 

This method worked for other browsers but not in Internet Explorer.

Answer №1

Personally, I believe that color values should be kept in CSS rather than Javascript. A potential solution to this issue could be organizing your code in the following way. It's important to use more descriptive class names instead of generic ones for better clarity.

JS

this.color = function(codigo){
            if(codigo == 10){
                return 'blue';
            }
            else if(codigo == 60 || codigo == 80){
                return 'green';
            }
            else if(codigo == 90 || codigo == 99){
                return 'red';
            }
            else{
                return 'darkblue';
            };
        };

HTML

<tr ng-class="'{{r.color}}'"> 

CSS

.blue {
    background: #00A6E8;
}
.green {
    background: #51BD53;
}
.red {
    background: #DE5F5F;
}
.darkblue {
    background: #F5AB2C;
}

Answer №2

To implement the ng-style, use this format:

<tr ng-style="{'background-color': r.color}">

For a demonstration, check out this plunker: http://plnkr.co/edit/KmIO5MVXlsBSitTXs19k?p=preview

If you prefer to utilize bgcolor, you can achieve it by using ng-attr-* in the following way:

<tr ng-attr-bgcolor="r.color">

I hope this explanation is beneficial.

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

Change occurring within a cell of a table that has a width of 1 pixel

In the code snippet below, there is a transition inside a table cell with a width of 1px to allow it to wrap its content. However, the table layout changes only at the end or beginning of the transition: var animator = document.getElementById("animator" ...

tips for transforming a javascript string into a function invocation

I am faced with the challenge of turning the string logo.cr.Button into a function call. Here is the code I'm working with: logo.cr.Button = function(){ //something } var strg = 'logo.cr.Button'; strg(); When I attempt to execute strg(); ...

consistent height across the div when expanding

There is a recurring issue I encounter where it takes too long for me to solve the problem. My goal is to ensure that the bootstrap boxes at the bottom of the page have the same height. I attempted to set a fixed height in pixels using my CSS, but this cau ...

Having trouble debugging JavaScript files in VS Code for .NET Core Web Application with AngularJS?

VS Code v1.64.2 .NET Core v3.1 AngularJS v1.8.2 I am currently attempting to utilize Visual Studio Code for debugging a .NET Core web application that incorporates AngularJS. I have successfully debugged breakpoints within .CS files after generating asset ...

Utilizing an ActiveX control embedded within another ActiveX control on a webpage

Struggling with accessing a non IDispatch method in an ActiveX control I created. In my web page, I have two separate Active X objects that were developed by me. The issue arises when I call a method on the first object, which returns an interface pointer ...

Center a single div vertically within a parent div by utilizing a fluid layout

Attempting to align text elements within a responsive layout presents challenges due to the fluid nature of <div> sizes. I recently discovered a fantastic method for horizontally and vertically centering a child <div> inside its parent <div ...

Footer is stubbornly stuck in the middle of the page, refusing to budge despite the

visit the live site here Despite setting the body height:100%, my footer continues to get stuck mid-page on certain pages such as about and contact. I have tried specifying the footer height and using position:fixed, position:absolute, and bottom:0, but n ...

Expanding Image with HTML and CSS: A Guide

In the process of creating my website, I encountered an issue with the logo placement. I wanted the logo to be in the top left corner, similar to the one shown in this image. Initially, everything was working fine until I made some adjustments to move the ...

Having trouble repositioning a div element in CSS

I am having an issue with my code. The problem I'm facing is that I am unable to move the green div.free_space below the other two divs, div.main_pic and div.navigation. I don't understand why this is happening. As I am still learning, I would g ...

Adjust the width of a box-shadow using percentage values in CSS

As we work on developing our tool according to the provided design, we are facing a challenge in drawing a line within a table row using box-shadow. The requirement is to have the line cover only 30% of the row width, rather than spanning across the entire ...

Steps for revealing all the information from a database when clicking on the 'Read More' button

I recently set up a database called Magazine, featuring a table named social_media. This table consists of 5 columns: ID, Headline, Author, Content Short, Content. The Content Short column contains condensed versions of the articles which are displayed on ...

One of the quirks of Angularjs is that the ng-enter animation will only be

The initial animation only occurs the first time. I am utilizing Angularjs version 1.2.22 Here is the CSS that I am using : .ng-enter { animation: bounceInUp 2s; } .ng-leave { animation: bounceOutUp 2s; } And this is the route configuration : ...

My React application is not showing the CSS styles as intended

In my project, I have a component file named xyx.js where I properly imported my scss file './xyz.scss'. Both of these files are in the same folder. Interestingly, when I view the styles using the Chrome scss extension, everything seems to be wor ...

What is the best way to position three SVG files in the center of a webpage?

I want to combine three separate SVG files to create one single graphic. The first SVG file is a red triangle, the second is a blue circle inside the triangle, and the third is a purple rectangle beneath the triangle with a little space in between. My obje ...

Using Bootstrap CSS and JavaScript specifically for carousel functionality

Custom Styles and Scripts for Bootstrap Carousel Using Carousel with Controls https://getbootstrap.com/docs/4.0/components/carousel/ <div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner ...

Struggling to generate an HTML table using JSON data

Struggling with generating an HTML table from JSON data, I'm inexperienced and having trouble with the logic. The JSON data I have needs to populate a complex dynamic HTML table. The design of the table is intricate, making it challenging for me to i ...

Position the button at the bottom of the page with MUI v5 in a React application

How can I ensure the button is always positioned at the center bottom of the page, regardless of the content height? This is a snippet from my code: const useStyles = makeStyles({ button: { bottom: 0, right: 0, position: "absolute" ...

Modifying the color of a GIF animated image using CSS

I'm currently working on an Angular application and I have a transparent GIF Loader image that I downloaded. I've been trying to figure out how to change the color of the GIF image, but so far, I've only been successful in resizing it. I sea ...

What is the best way to access the watchExpression within the listener of the $watch function?

Is there a way to access the watchExpression inside the listener function? My goal is to extract parameters from the watchExpression. $watch(watchExpression, [listener], [objectEquality]); ...

Difficulty adjusting table heights in Dreamweaver, Struggling to set table height with <p style declarations

I'm currently designing an email signature in Dreamweaver using a table. However, I encountered an issue when I added the <p=style tag to customize my font size and color - it caused my table heights to change unexpectedly. Despite trying various s ...