Unable to apply 3rd condition with ngClass into effect

I've been attempting to incorporate a third condition into my ngClass. Initially, I managed to get two classes working in my ngClass to change the row colors alternately.

[ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0}"

Now, I'm trying to introduce a third class and condition where the mat-list will display a border line at the top of the mat-list-item. However, upon adding the third condition, it's throwing an error.

[ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0, borderTopClass : operator === 'fas fa-equals'}"

When I make this addition, I encounter the following confusing error message:

Parser Error: Missing expected : at column 47 in [{ totalrow:i%2 != 0, odd:i%2 == 0, borderTopClass : operator === 'fas fa-equals'}] in

Below is the code with the ngFor loop:

<div class="ng-container" *ngFor="let operator of operatorList; let i = index">
    <mat-list-item 
        fxLayoutAlign="start" 
        style="padding-left: 0px; padding-right: 0px;" 
        [ngClass]="{ totalrow:i%2 != 0, odd:i%2 == 0, borderTopClass   : operator === 'fas fa-equals'}">
            <i class="{{operator}}"></i>
    </mat-list-item>
</div>

Any assistance on this issue would be greatly appreciated.

Answer №1

It seems like further clarification is needed to explain how this code functions.

<div [ngClass]="{
  'is-active': condition,
  'is-inactive': !condition,
  'multiple': condition && anotherCondition,
}">

The multiple class will only apply when both conditions are met, not just one or the other.

If you want to add a third condition, you can do so like this:

'multiple': condition && anotherCondition && thirdCondition

Here's a link to a StackBlitz where you can see the provided code in action without any errors. Let me know if you need any more assistance.

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

The angular schematic workflow encountered an error while attempting to create a new project

Successfully installed Angular CLI, but I encountered an issue while creating a new project using 'ng new project name'. Some packages were created, but the installation failed with an unexpected end in JSON while parsing near.....'A85qs.... ...

The modal functionality in AngularJS doesn't seem to be functioning properly

I am currently working on an Angular application where I want to implement a button that, when clicked, will open a pop-up window displaying a chart. Below is the button code: <div style="padding-top:50px;padding-left:10px;"> <button type="butto ...

The output of `.reduce` is a singular object rather than an array containing multiple objects

Building on my custom pipe and service, I have developed a system where an array of language abbreviations is passed to the pipe. The pipe then utilizes functions from the site based on these abbreviations. Here is the parameter being passed to the pipe: p ...

How is the height and width of the header determined?

When examining the theme by clicking "inspect element" on the green portion (<header> ), you will notice that the height and width properties have pixel values that change dynamically as the window is resized. So, where do these values originate fr ...

Creating an element that remains in a fixed position in relation to its parent container, rather than the entire screen - here's how

Encountering an issue where, upon user scrolling down, a portion of the sidebar becomes fixed in position. However, when attempting to apply CSS for fixing the sidebar element, it ends up fixed to the entire screen instead of just within its parent contain ...

Is there a way to adjust the positioning of the center item in owl carousel 2 after applying a scale transformation of 2.0, without it getting cropped vertically?

I am having an issue with using Bootstrap card and owl carousel 2. When I apply transform: scale(2.0) to the center item, it becomes vertically cropped instead of staying centered. It overflows in the owl-stage section. Is there a way to fix this problem? ...

Is it possible for the Angular service worker to refresh cached data keys?

My website is powered by express.js with index.html being rendered through the EJS Template Engine. Upon initially visiting my website, index.html displays correctly. However, upon refreshing the page, index.html is loaded from the service worker's ...

Utilizing jQuery to Adjust Tab Transparency

I'm trying to add some opacity to my jQuery tabs, but so far I've only been successful with accordions. Any tips or tricks for achieving this effect with tabs? Styling with CSS .ui-tabs{ background-image: none; background: rgba(204, 204 ...

Button with small width containing an icon and text

I am trying to create a simple HTML button that has an icon on top and a description below it. <div class="mybtn"> <div><img src="someimage.png"></div> <div>Button description</div> </div> My question is, ...

What's the best way to adjust text color to black or white for maximum contrast when the background changes?

Currently, I am attempting to replicate the email element found on this website: .custom-blend-mode { mix-blend-mode: difference; } Although I have managed to make it work, it results in a change to the opposite color. Ideally, I would like it to remai ...

Improved efficiency in CSS for left transition animations

Here is the current code I am using: .s2 { top: 150px; left: 20px; position: absolute; transition: left 300ms linear; } I am currently updating the left position dynamically using JavaScript based on scroll events. However, I have noticed that th ...

What is the best way to transform promise-based code into observables?

I'm looking to convert the code from using promises to observables. However, when I try to do this, I encounter the following error: this.options.upload(...).then is not a function embedFile(file: File, handlerId: string) { this.options.uplo ...

Revamp the Bootstrap 4 Form Check: Rearrange Options from left-to-right and top-to-bottom to top-to-bottom and left-to-right

I am currently using a Bootstrap form that displays a checkbox with 13 different options, including: Urban Plans Commercial Entity Cultural Approval Education Sector Hospitality Industrial Design Interiors Art Leisure/ Sporting Residential Care Retail Spa ...

Discovering the element within an array using the post method in TypeScript

When I log in to the app, it sends me a JSON file with my user permissions like this: {"StatusCode":0,"StatusMessage":"Authenticated Successfully", "Token":"eyJhbGciOiJIUzI1NiIs", "StatusDescription":{ "Role":"admin", "Permissions":["homeb ...

Angular: Verify that all services are fully executed before proceeding to the next step

We have adopted Angular for our project. Our component receives data from an API, which is then processed by Data Services. These services transform the data by combining first and last names, rounding dollar amounts, performing calculations, etc. The fina ...

How can one element be made to rely on the presence of another element?

I'm currently working on my portfolio website and encountering an issue. Whenever I hover over an image of a project, the image expands in size, becomes less transparent, and a description of the project pops up. However, I would like to include a lin ...

Printing a React component using a button causes formatting related to className to be lost, while printing it inline preserves the formatting

I've hit a roadblock in trying to figure out the React and printing issue for the past week and a half, and it feels like I'm going in circles. Despite finding some helpful solutions on Stack Overflow, none of them seem to work completely for me ...

Regular Expressions: Strategies for ensuring a secure password that meets specific criteria

Struggling to craft a regex for Angular Validators pattern on a password field with specific criteria: Minimum of 2 uppercase letters Minimum of 2 digits At least 1 special character. Currently able to validate each requirement individually (1 uppercase ...

What is the best way to assign a value to an option element for ordering purposes?

My select element is being populated with fruits from a database, using the following code: <select name="fruitsOption" id="fruitsOptionId" ngModel #fruitRef="ngModel"> <option *ngFor="let fruit of fruits">{{fruit}}</option> </selec ...

The functionality of the click event attached with the addEventListener is

I have a unique project where I am developing a user interface for a paper-rock-scissor game. To create the UI, I included four buttons: "Start game," "rock," "paper," and "scissor." Initially, I wrote separate code for each button, which worked perfectly ...