ng-class not updating using a combination of object and string

I am just starting to learn angular js and I recently came across the ng-class directive. Below is an example of how I have used it:

ng-class="[{'highlighter-row-Class' : (file.id == 1 && file.processed),
    'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 
    'failed-doc': !file.processed }, getClassForHrms(file)]"

CSS Styles

.missingfieldspresent {
  color: red;
}
.documentduplicate {
  color: purple;
}
.documentuploadfailed {
  color: deeppink;
}

JavaScript Function

$scope.getClassForHrms = function (file) {
    if (file.attributes.hrmsMandatoryFieldsMissing) {
        return "missingfieldspresent";
    } else if (file.attributes.isDocumentDuplicated) {
        return "documentduplicate";
    } else if (!file.attributes.isDocumentDuplicated) {
        return "documentuploadfailed";
    }
};

Rendered HTML Output

<tr ng-repeat="file in processResumeFiles" ng-class="[{'highlighter-row-Class' : (file.id == 1 &amp;&amp; file.processed), 
    'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 
    'failed-doc': !file.processed }, 
    getClassForHrms(file)]" class="ng-scope [object Object] documentduplicate">

Currently, when rendering the HTML, it seems like the class is not being added as expected due to an object being returned. Can anyone suggest a solution for this issue?

Any help or suggestions on how to resolve this would be greatly appreciated.

Answer №1

The ng-class syntax appears to be a bit off (remove the square brackets).

ng-class="{'highlighter-row-Class' : (file.id == 1 && file.processed),
    'bold-row-Class' : lastSelectedResumeId == file.attributes.name, 
    'failed-doc': !file.processed }, getClassForHrms(file)"

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 reason behind getComputedStyle having visibility set to visible?

What is the reason behind getComputedStyle always returning element visibility as visible even when no explicit visibility has been set? For instance: getComputedStyle($('#block1')[0],null).visibility; --- "visible" Meanwhile: $('#block1&a ...

JavaScript generates a series of checkboxes dynamically, all lined up in a single row

I am currently working on a script where I iterate over objects and aim to display the text of each object on a new line in the list format, along with a checkbox next to it. Despite successfully printing everything with a checkbox, the issue I am facing i ...

Avoid multiple delays when clicking the identifier

I came across this code snippet: $(element).on('click', function() { $this.closest('div').before('<span id="message" style="display:none"></span>'); $('#message').fadeIn().delay(5000).fadeOut(); ...

Displaying information from database using AngularJS

How can I display data from a database on my webpage? This is the JavaScript code: $scope.save = function() { var data = { subject: $scope.composeStory.subject, body: $scope.composeStory.body } $http.post( "insert.php", { ...

The ng-click directive does not function properly when used in conjunction with dynamic HTML

My issue involves creating dynamic html in HTML where ng-click is not functioning properly. Here is my code snippet: window.imagePicker.getPictures( function(results) { for (var i = 0; i < results.length; i++) { console.log(&apo ...

Simple method for sending a JavaScript array or its data to a servlet utilizing jQuery's ajax() functionality

Seeking advice on passing data from a Javascript array to a servlet using the ajax() method of jQuery. Is there a straightforward way to accomplish this task? The index values in the array are meaningful numbers that are not in order, which complicates th ...

Spinning a div using Jquery

I'm having trouble getting a div to rotate. Despite checking the console, I haven't encountered any warnings or errors. If you'd like to see the JSFiddle version of it, feel free to take a look. Below is the code snippet I've been usi ...

Retrieving Content within <b></b> Tags from an RSS Feed XML (with Javascript/React)

After parsing an RSS Feed from Upwork, I have extracted job item data points such as title and link. However, a significant amount of the necessary information about each job (category, skills, etc) is buried within the "content" data item as one large blo ...

React.js JSX side by side components

When running the code below, I encounter an exception related to parsing in React. How can I resolve this error where JSX elements must be wrapped in an enclosing tag? Error: Line 48: Parsing error: Adjacent JSX elements must be wrapped in an enclosin ...

Tips for inserting data into a PHP modal using MySQL and Ajax

Here is the code snippet I've written: <div class="container"> <div class="row"> <div class="col-md-3"> <div id="accordion" role="tablist" aria-multiselectable="true"> <div class="card"> ...

Inserting data into a JavaScript database

When attempting to add a new row to a datatable and submit it to a JSP for database insertion, an error is encountered. The error message reads: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r ...

How should I manage objects that are passed by reference in the context of functional programming?

Lately, I have been experimenting with some code in an attempt to delve deeper into functional programming. However, I seem to have hit a snag. I am struggling with handling an object. My goal is to add key-value pairs to an object without reassigning it, ...

Error: Attempting to access a property called 'name' on an undefined variable leads to a TypeError

I am a beginner with MongodB and nodejs. I have successfully implemented the GET method, which returns an empty array. However, when I tried to use POST in Postman for "categories," I encountered this error message: ExpressJS categories route app.js Err ...

Leverage Summernote in conjunction with Vue components to dynamically switch their locations

I am experiencing a strange behavior with Vue components created using v-for. Each component has a textarea for summernote, and initially everything works correctly. The editor loads the text and updates it when edited. However, when the position propert ...

What is the best way to horizontally center an image in Bootstrap 4 while having a fixed-top navbar and preventing vertical scrollbars?

I am struggling to achieve the desired outcome, which is depicted in this image: https://i.sstatic.net/i6X0j.jpg Specific requirements for this project include: The image must be responsive A fixed-top navbar should remain visible No vertical scrolling ...

Could you please help me identify the root of this error in AngularJS?

I have just started learning AngularJS. After updating to version 1.3.6, I encountered the following error: Error: [ng:areq] http://errors.angularjs.org/1.3.6/ng/areq?p0=myController&p1=not%20a%20function%2C%20got%20undefined What could possibly be u ...

Scrolling Horizontally, Tailored to Fit Content's Width

I am working with a page layout that consists of a wrapper, content div, and two item divs. The wrapper has a width of 320px, while the items together measure around 600px. I want the two item divs to display inline, allowing the content to scroll horizont ...

Problem encountered when attempting to insert a new division into an existing flexbox container

I'm in the process of designing a basic login page using HTML/CSS. To center the box on the screen, I opted for a flexbox layout. So far, I have successfully positioned the Username/password fields and login button just the way I want them. The only t ...

Executing a function within the same file is referred to as intra-file testing

I have two functions where one calls the other and the other returns a value, but I am struggling to get the test to work effectively. When using expect(x).toHaveBeenCalledWith(someParams);, it requires a spy to be used. However, I am unsure of how to spy ...

Utilizing variables within the bgStretcher function

As a beginner in php programming, I have a query that needs clarification: Can I use variables to set the width and height values of a bgStretcher image? <?php $arrPath=array("bg" => "http://mydomain.com/myimage.jpg"); $w=1500; $h=800; ?> $(doc ...