September 20, 2025
Conditional Fomatting in CSS with AngualrJS1

What is Conditional Formatting in CSS and How to do it With AngularJS (ng-class)

I’m so happy to have you again!


In this brief blog, I am going to help you understand conditional formatting and how to apply it using css.

 

What is Conditional Formatting?
Conditional  Formatting also called Conditional Styling is a situation where styles are apply to html element based on conditions that may changes at view time. For example, based on values from data in a database.

 

When to use Conditional Formatting
A typical example of when you can use conditional formatting is when the color of the text needs to change depending on the status. For example:

  • Status: Pending
  • Status: In Progress
  • Status: Completed

How to Apply it In angularjs, you can achieve conditional formating using either

  • ng-class
  • ng-style

Using ng-class Cleate two classes called Pending and Completed

css Style

.pending 
{
   color: red;
}
.completed
{
color: green;
}

 

Then in your table use the html markup below:

 

<table ng-repeat = "row in activities" width="364" height="140" border="1">
    <tr>
      <td>Create C# Tutorial </td>
      <td ng-class="{'pending':row.status === 'Pending'}, 'completed':row.status ==="Completed>{{row.status}}</td>
    </tr>
    <tr>
      <td>Do a Presentation on .Net</td>
      <td ng-class="{'pending':row.status === 'Pending'}, 'completed':row.status ==="Completed>{{row.status}}</td>
    </tr>
</table>

 

The output is as shown below:

 

Let’s now see how to do it using ng-style

 

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
대구오피
대구오피
6 years ago

I have been exploring for a little for any high quality articles or blog posts on this kind of house .
Exploring in Yahoo I eventually stumbled upon this site.

Reading this information So i am glad to exhibit that I’ve an incredibly excellent uncanny feeling I discovered
exactly what I needed. I such a lot without
a doubt will make certain to do not disregard this web site and give it
a look regularly.

steve
steve
5 years ago

I don’t know anything about coding, but where the end brace is and where the close ” is look wrong…

{{row.status}}