Using Angular to pass a variable in nth-child with CSS

I am trying to pass a variable from the model ts into a specific nth-child element, but I am struggling with how to accomplish this. My current code snippet looks like this:

ts model:

@Input() public limit: number

scss:

.collapsed-list {
  max-height:15rem;
  overflow: hidden;

  .expandable:nth-child(${limit}) {
     color: red;
  }
}

Any suggestions on how to achieve this would be greatly appreciated. Thank you!

Answer №1

One way to address this issue is by applying a specific style when the counter reaches the limit specified in the template.

.max {
   color: red;
}
    
<div class="collapsed-list" *ngFor=" counter; let index ">
  <div [class]="index === limit ? 'max' : ''"
</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

"Utilize ngClass to dynamically update the styling of elements

Hello, I've encountered an issue with a basic Angular component. I'm using a reactive form to input text and then displaying the text using ngFor loop. However, when I try to set one element as active on click, all elements end up with the active ...

Emphasize a specific line of text within a <div> with a highlighting effect

I'm looking to achieve a similar effect as demonstrated in this fiddle As per StackOverflow guidelines, I understand that when linking to jsfiddle.net, it's required to provide some code. Below is the main function from the mentioned link, but f ...

Centering content vertically within a Bootstrap 4 table

I'm attempting to center the content vertically in this table using the align-middle class but it doesn't seem to be working. How can I get it to work? tr, td, p, a { border: 1px solid black; } <link rel="stylesheet" href="https://stackpa ...

Unable to establish a cookie on an Angular client hosted anywhere except for 'localhost'

Utilizing an express server as the backend and an angular client as the frontend. The express server is hosted on port 3001, while angular is on port 4200. Everything works perfectly when running on localhost. However, when attempting to host Angular on a ...

What is preventing me from adjusting the width of an image that extends outside of its parent container, even though I am able to modify the height?

I am facing an issue with a div on my website that has specific properties: #viewport{ overflow: hidden; display: block; position: relative; width: 323px; height: 323px; } Embedded within this div is an element with the following prop ...

Show detailed information in a table cell containing various arrays using AngularJS

After integrating d3.js into my code, I now have an array with key-value pairs. Each team is assigned a key and its corresponding cost is the value. When I check the console log, it looks like this: Console.log for key and value Rate for current month [{ ...

Can someone guide me on how to customize the CSS of a fab element in Onsen UI?

I've been struggling to change the background color or border of the onsen fab element. I'm working with angular 2 and onsen v2. Even after trying the !important rule, my CSS doesn't seem to take effect unless I disable the fabs default styl ...

What is the best way to create a footer in this scenario and is there a method to perfectly center an

What is the best way to position the footer at the bottom of the page without overlapping the top content? Is there a method to center both the height and width of the header element on the page? Can you review the layout of this webpage and provide feed ...

Activate the function when the @Input() is modified

In my parent component, I have the following code in the parent.component.html: <app-child [idElement]=(idElement)></app-child> The child component has an input parameter defined as follows: @Input() idElement : number; Additionally, there ...

Maintain font kerning for span elements that are not displayed inline

I am looking to add some transform effects to individual letters in a word. To achieve this, I have enclosed each letter within a span element. However, when setting the display of these spans to inline-block, the font kerning gets disrupted. I have exper ...

Ways to format table using flex-wrap sans the use of flexbox

My HTML and CSS structure is as follows: .item { background: white; padding: 5px; display: inline-block; text-align: center; } .item > div { background: yellow; width: 60px; height: 60px; border-radius: 50%; display: table-cell; ...

What are the steps to showcase the content of a Typescript file on an HTML webpage?

We are looking to create a sample gallery with source code examples. Including typescript, html, and HTML files to showcase similar to the Angular.io component samples pages. Is there a way to extract the source code from a typescript file within our pro ...

JavaScript: The functionality of calling functions through buttons ceases to function once the page is updated without reloading

I am trying to create a program that consists of one HTML page, where I can dynamically update and populate it with different elements using JavaScript. The main feature of the program is a button that remains constant in every version and displays a mod ...

Learn how to easily reset the index value within the same template in Angular

In my template, I have 3 tables with the same JSON data as their parent elements. <tbody> <ng-container *ngFor="let row of reportingData.RecommendationData; let i=index"> <tr *ngIf="row.swRecommendations"> <td& ...

Encountering an error with "unexpected token import" while utilizing localize-router in an Angular 4

I am currently working on building an Angular 4 app with server-side rendering and language-specific route paths. I am using Angular CLI version 1.5.0-rc1 for this project. While everything seems to be functioning fine, I am facing a problem with incorpor ...

Unable to locate module: The system was unable to find the specified module '@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js'

After encountering an error with Mat Dialog boxes close button not working on IOS devices (refer to Stack Overflow), I decided to downgrade my Angular project from version 14.0.0 to 13.0.0. I followed a solution provided in another Stack Overflow thread. H ...

Error message: "Upon initial loading, Angular and Firebase are unable to map undefined"

After the initial load, it functions properly. However, I am seeking a way to implement a promise to prevent data mapping before it has fully loaded. Upon the first loading of the site, the error below is displayed. This issue may arise from attempting to ...

What is the best way to add multiple elements to an array simultaneously?

I am facing an issue with my array arrayPath. I am pushing multiple values into it, but there are duplicates in the data. When the value of singleFile.originalFilename is a duplicate, I do not want to push that duplicate value into arrayPath. How can I ach ...

The program encountered an issue with binding to 'formGroup' as it is not recognized as a valid property of 'form'. Error code: NG8002

Upon running the ng serve command, I encountered an error. Here is a link to view the error: error To provide context, here is my directory structure: structure For reference, here are the related files in my project: app.component.html app.component.t ...

Ways to insert additional panels prior to and after a selected panel

A button is provided in the report designer detail band that, when clicked, should add new panels immediately before and after the detail panel. $parentpanel = $this.parents(".designer-panel:first"); This code snippet is used to locate the parent panel u ...