Issue with ngClass in Angular 9 when deployed to production environment

I am encountering an issue with a [ngClass] on my Production environment, which was working correctly in the local environment. Despite not being able to replicate the problem locally, debugging on production reveals that the class is initially applied but then removed afterwards.

If the [ngClass] continues to malfunction on PROD, what alternative approaches can be considered?

CSS

#main .drawing-select {
  min-width: 285px;
  margin-bottom: 15px;
}

#main .highlight {
  border: 3px solid  #66bb6a;
}

HTML

<div cdkDropList class="drawing-select-container" (cdkDropListDropped)="drop($event)">
  <div *ngFor="let c of configs;let i = index" cdkDrag>
    <mat-card [ngClass]="outLine(c.UpdatedTimestamp)" (click)="selectConfig(i)" fxLayout="column"  fxLayoutAlign="center center"
      @fadeInAnimation>
      <img src="{{ c.SignedUrl }}&width=200&height=150" />
      <span>{{c.Content.Title}}</span>
    </mat-card>
  </div>
</div>

TS

 public outLine(timeStamp: Date): any {
    const date = new Date();
    const currentDate = moment(date, 'YYYY-MM-DD').add(-2, 'd').toDate();
    timeStamp = moment(timeStamp, 'YYYY-MM-DD').toDate();

    const value = timeStamp >= currentDate ? true : false;
    return {
      'highlight': value,
      'drawing-select': true
    };
}

Answer №1

Give [class.className]= a shot, like so:

<mat-card [class.selected-section]="true" [class.highlighted]="outLine(c.LastModified)['highlight']" (click)="chooseOption(i)" fxLayout="column" fxLayoutAlign="center center" @fadeInAnimation>
  <img src="{{ c.ImageLink }}&width=200&height=150" />
  <span>{{c.Data.Title}}</span>
</mat-card>

On the flip side, at times, the fxLayoutAlign directive can overwrite dynamic Class attributes.

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

After selecting a subitem, the side menu will automatically close

I designed a side menu that expands to reveal submenus. However, when I click on a subitem within a submenu, the entire list closes. The HTML, CSS, and JavaScript code all appear to be correct as the template is functioning properly. But as soon as I ins ...

Tips for handling CSS loading delays with icons in OpenLayers markers

When using openlayers (v4.6.4) with font-awesome as marker icons, the icons do not display upon first load (even after clearing cache and hard reload). Instead, I see a rectangle resembling a broken character. It is only on the second load that they appear ...

Positioning icon/image beside the input box

Currently, I have a form with two buttons in a row and an icon (paper clip) that I am attempting to align next to the buttons using UIKit. However, I am facing challenges in getting the alignment right without affecting the size of the elements. Below is a ...

The sticky navbar fails to stay in place when the content becomes too lengthy

This is my current state of code (minified, for explanation only) index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-w ...

Unable to locate the 'NodeJS' namespace along with node types

I encountered an error in my web application: ERROR in node_modules/zone.js/dist/zone.js.d.ts:600:21 - error TS2503: Cannot find namespace 'NodeJS'. 600 declare var global: NodeJS.Global; Even after adding the types": ["node"] pr ...

Find the final element that does not include a particular class

Looking for the best way to identify the last item in a list without a specific class? Learn how to write code that can check for the absence of a class name. $('ul li:last') $('ul li:not(.special)') ...

Localhost Delay in XAMPP

As I work on developing my own website, I have opted to use XAMPP for hosting. After making modifications to the CSS, HTML files, and replacing the existing images with new ones in the designated folder, I encountered an issue. Despite restarting and re-i ...

Exploring the ins and outs of data exchange within Angular 2

I'm currently in the process of developing an angular2 application. One of the components in my project is the MountainListComponent, which is composed of other components (although this detail is not crucial) and is nested within a parent component. ...

Can someone explain how to implement document.querySelector in TypeScript within the Angular framework?

I am tackling the task of creating a login/register form that allows users to switch between the two forms with the click of a button. The goal is to only display one form at a time. Initially, I implemented this functionality in a basic HTML file and it w ...

The show/hide feature is malfunctioning

I need help with my PHP page where I display multiple choice questions from a database along with options and answers. Currently, I am using an HTML button to show/hide the answers but it only works for the first question. When I click on other questions, ...

Update the SCSS variables for printing purposes

Is it possible to adjust variables in SCSS specifically for printing purposes? Here are some current variables I have: $baseFontSize : 12px; $defaultSansSerif: "Helvetica Neue", Helvetica, Arial, sans-serif; $defaultSerif : Times, "Times New Roman" ...

The JSX function seems to be malfunctioning, as the function part is not displaying on the webpage as intended

This code snippet is a part of a React component in a project. I have imported a CSS file for styling and have already integrated Material UI. However, the function for the new article is not displaying on the webpage as expected. import "./Widgets. ...

Center the panel on the page and decrease its width using Bootstrap

I recently incorporated a Bootstrap panel above a search results table - my first experience working with Panels. This panel contains a form with a select menu, allowing users to filter the list of search results based on their selections. Currently, the ...

Sending JSON Object using NavController

I am trying to send a JSON Object to another Page in my Ionic 2 application. However, when I attempt to do so, I encounter the error: Cannot read property 'user' of undefined. While researching for a solution, I came across a similar question ...

When the jquery.show() function is invoked, scrollbars are displayed on the screen

I am encountering an issue with a flydown menu that includes a scrollable div. The div is about 400 pixels in height, causing scrollbars to appear in the drop down menu. When I hover over it, I trigger the show method as follows: $("#flydown").show(); Al ...

Creating a persistent hover effect

Utilizing primarily CSS, along with background images and adjacent selectors, I am creating a page that displays unique human-readable text information when the user hovers over horizontally stacked images. The textual information is presented in a div on ...

Implementing top level await feature in Angular 16

Issue with ./node_modules/lucid-cardano/esm/src/core/core.js - Error: Module parse failed due to the top-level-await experiment not being enabled (experiments.topLevelAwait must be set to true to enable it). The file was processed using these loaders: ./n ...

what is the best way to position a glyphicon next to a form?

Forgive me for asking such a basic question, but I struggle with aligning and positioning elements. Here is my issue: https://i.sstatic.net/Uy6XB.jpg https://i.sstatic.net/TTs6V.jpg All I want is for the glyphicon to be displayed next to the textfield, ...

The child component notifies the parent to update itself, then the parent proceeds to update the input value of another child

This question may have been asked numerous times before, but despite trying various approaches such as using a subscription on the child component and ngOnChanges, I am still unable to get it to work. Here is the basic structure of the issue in my project ...

What could be causing the issue with setting the right margin (element.style.marginRight = xxx) not working?

I used JavaScript to set the margin-right of a div when the window is resized. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device- ...