What is preventing NgClass from applying the CSS styles?

I'm currently facing an issue in Angular2 where I am trying to apply different styles using ngClass within an 'NgFor' loop, but for some reason, it's not working as expected.

Apologies for any language errors.

<div class='line'></div>
<clr-icon *ngFor="let step of steps; let i = index" shape="circle" 
class='circle' attr.ng-class="circle{{ i + 1 }}"
size="36">
</clr-icon>
<clr-icon *ngIf="steps.length == 1" attr.ng-class="circle{{ 2 }}" shape="circle" class='circle' size="36"></clr-icon>

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.mycontainer {
  position: relative;
  width: 100%;
  display: block;
}

.step {
  position: absolute;
  left: 0%;
  width: 100%;

  .circle {
    color: black;
    margin-top: -30px;
    background-color: white;
  }

  .circle1 {
    position: absolute;
    left: 0%;
  }
  .circle2 {
    position: absolute;
    right: 0%;
    background-color: black;
    color: yellow;
    /*@calcularposicion();*/
  }
}

.line {
  height: 5px;
  width: 100%;
  background-color: green;
}

Even though the second circle should appear with a 'yellow' color, it is not displaying anything. Upon inspecting the HTML, I can see that the classes 'circle' and 'circle2' are present.

Answer №1

Update the usage of attr.ng-class to [ngClass]. Remember, NgClass is not just an attribute but a directive offered by Angular.

<clr-icon *ngFor="let step of steps; let i = index" [ngClass]="'circle' + (i + 1)"></clr-icon>


<clr-icon *ngIf="steps.length == 1" [ngClass]="'circle2'"></clr-icon>

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

Arranging div blocks in columns that are seamlessly aligned

I am dealing with a situation where I have several boxes or blocks arranged in a 3-column layout. These boxes are styled using properties like float: left, width: 33%, but they have varying heights. Is there a way to make sure that the boxes always fill i ...

Update in slide height to make slider responsive

My project involves a list with text and images for each item: <div class="slider"> <ul> <li> <div class="txt"><p>First slogan</p></div> <div class="img"><img src="http://placehold.it/80 ...

Ratios for Sizing Bootstrap Columns

The Bootstrap grid system consists of 12 columns in total. I am looking to utilize all 12 columns on the page. However, my goal is to have the first 6 columns on the left side be half the width (50%) of the columns on the right side. This means that the ...

Navigate the child div while scrolling within the parent div

Is there a way to make the child div scroll until the end before allowing the page to continue scrolling when the user scrolls on the parent div? I attempted to use reverse logic Scrolling in child div ( fixed ) should scroll parent div Unfortunately, it ...

Guide on showing error message according to personalized validation regulations in Angular 2?

Utilizing a template-driven strategy for constructing forms in Angular 2, I have successfully implemented custom validators that can be utilized within the template. However, I am facing an issue with displaying specific error messages associated with dis ...

Creating an eye-catching animation in Angular 2+ by applying a checkbox check effect to each checkbox dynamically generated within a loop

When I integrated a CSS animation for checkbox "cards" into an Angular project, the transition ceased to function properly. I have limited experience with Angular and am trying to work with existing code. While I managed to get a basic animation working wi ...

"What is the best approach to adjusting the width of one div based on the width of another div using CSS Grid

As a beginner in programming, I'm trying to work with CSS Grid but facing some challenges. My goal is to create a component with two columns: the left column should have a width of minmax(570px, 720px), and the right column should be minmax(380px, 10 ...

Return the reference to an injected service class from the location where it was implemented

Is it feasible to return a reference from a component class with a custom interface implemented to the injected service class in my Angular 6 project? Here is an example of what I am aiming for. ServiceClass @Injectable() export class MyService { co ...

What is the best way to ensure that images on a webpage adjust to a maximum width without distorting smaller images?

I'm working on my website blog and I need to create a specific area for images at the top of my articles. I want these images to have a maximum width so they don't exceed a certain size, but I also want smaller images to remain unaffected. Curren ...

Need help positioning this HTML iframe on my webpage?

Can anyone help me figure out how to position this HTML i-frame in a specific place on my webpage? <div style="overflow: hidden; width: 333px; height: 156px; position src="h: relative;" id="i_div"><iframe name="i_frame"http://url.com/click.php?a ...

Using Angular 2: A Beginner's Guide to Navigating with the Latest Angular 2.0.0-rc.1 Router

As I embarked on a new Angular 2 project, I was puzzled to discover that I inadvertently installed two different versions of the angular router: "@angular/router": "2.0.0-rc.1", "@angular/router-deprecated": "2.0.0-rc.1", Despite my best efforts, I co ...

Explicitly employ undefined constants deliberately

So I am working on a project called WingStyle: https://github.com/IngwiePhoenix/WingStyle. It is still in the development phase, and I'm looking for ways to improve its functionality. One thing I want to address is the use of quotes. For example, whe ...

What is the best way to expand my navigation bar to fill the entire width of my div?

A big shoutout to @seva.rubbo for fixing the issue! Check out the updated code on JSFiddle I recently designed a layout with a fixed width div of width: 900px;. I centered this div, leaving blank spaces on either side. Now, I'm looking to add a navig ...

Instructions for connecting a button and an input field

How can I connect a button to an input field? My goal is to make it so that when the button is clicked, the content of the text field is added to an array (displayed below) const userTags = []; function addTags(event) { userTags.push(event.target.__ wha ...

Extend the height of bootstrap 5.2.0 row/column to reach the bottom of the page

I'm having difficulty extending the left navigation section to reach the bottom of the page while remaining responsive. Despite trying various solutions like h-100, flex-grow, min-vh-100m self-align: stretch, nothing seems to solve the issue. Check o ...

Achieving opacity solely on the background within a div class can be accomplished by utilizing CSS properties such

Whenever I adjust the opacity of my main-body div class, it results in all elements within also becoming transparent. Ideally, I would like only the gray background to have opacity. See below for the code snippet: <div class="main1"> content </di ...

Next JS Event Listener Failing to Detect Scroll Events

Currently, I am attempting to change the state and display a shadow in the navigation bar when the user scrolls, but for some reason it is not detecting the event. I am working with nextJS 13 and tailwind css. const [shadow, setShadow] = useState(false) ...

What is the best way to change the height of a div element as the user scrolls using JavaScript exclusively?

Coding with JavaScript var changeHeight = () => { let flag = 0; while(flag != 1) { size += 1; return size; } if(size == window.innerHeight/2){ flag == 1; } } var size = 5; document.body.style.height = &qu ...

Injecting PHP variables into CSS code right from a PHP file

$a = "ABCD"; ?> <link rel='stylesheet' type='text/css' href='others.php' /> <style> .page-title { text-indent: -9999px; line-height: 0; } .page-title:afte ...

Troubleshooting nested form controls in Angular v12

When populating a dynamic form with data retrieved from the backend API, I encountered an issue with my code: sections: this.formBuilder.array([]) Within this code block, there is a nested array that is populated as follows: result.formSections.forEach(x ...