modifying checkbox appearance in Angular depending on certain criteria

Is it possible to update the checkbox color and text color based on certain conditions? Currently, my output shows that the checkbox is checked but the check icon is hidden. I would like the check mark to be visible when the checkbox is checked, and also change the text color from white to black. Thank you for your help.

#current output https://i.sstatic.net/uDJJI.png

#my target design (it should look like this) https://i.sstatic.net/YMSG8.png

<div *ngFor="let subtenant of currentSubtenants; let i = index;" class="subtenant-form-btn-group"  [ngClass]="{'v-bg-color': currentSelectedTenants(subtenant)}">
              <div class="deal-form-btn-group-radio">
                <div class="pharmacy-checkbox">
                  <mat-checkbox
                   color="accent"  
                   [(ngModel)]="dealDispositionFormFields.currentSubtenants"
                   [checked]="currentSelectedTenants(subtenant)" 
                   (change)="changeCurrentSubtenants($event,subtenant)"
                   style="margin-left:10px;">
                  <mat-label class="subtenant-label" style="color:rgba(0, 0, 0, 0.87)">{{subtenant.subtenantName}}</mat-label>
                  </mat-checkbox>  
                  </div>
              </div>
              <div >
                <div class="flex-column">
                  <mat-label class="subtenant-label">Current Lease Expiration</mat-label>
                  <div class="subtenant-label">{{subtenant.currentLeaseExpiration}}</div>
                </div>
              </div>
            </div>

Answer №1

If you need to dynamically apply classes in Angular, ngClass is the way to go.

More information about ngClass here

<div
  *ngFor="let item of itemList; let i = index;"
  class="dynamic-class"
  [ngClass]="{yourClassName: condition}"
  >
    ...
</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

Maintaining the essence of generics while encapsulating functions

I am currently facing a challenge in defining a function that can wrap any other function while maintaining the parameter types and return type. I have managed to achieve this when the function does not use generics, but I am encountering difficulties wi ...

7 Tips for Renaming Variables in VSCode without Using the Alias `oldName as newName` StrategyWould you like to

When working in VSCode, there is a feature that allows you to modify variables called editor.action.rename, typically activated by pressing F2. However, when dealing with Typescript and Javascript, renaming an imported variable creates aliases. For exampl ...

Leveraging Angular OpaqueToken for Injecting Config Object Does Not Display Type Errors

When using an OpaqueToken to inject a config object into the application in Angular, I followed the documentation and was able to successfully DI the config into a component and retrieve values. However, I encountered an issue when trying to enforce type c ...

Challenge encountered when utilizing angular 2 RC router for programmatic route navigation

Currently, I am utilizing the RC router in version rc1 with two defined routes as shown below: @Routes([ {path: '/', component: HomeComponent}, {path: '/signin', component: SigninComponent}, {path: '/dashboard', c ...

What are the reasons behind the issues encountered when enabling "Optimization" feature in Angular that affect the proper rendering of PrimeNg elements?

Angular Version : 9.x Primeng Version : 9.x We've encountered an issue with PrimeNg elements not rendering correctly in our dev/prod environments, although they work fine in the local environment. After some investigation, we found that the culprit ...

Error encountered with Custom Component: Unable to establish binding for 'ngModel' as it is not recognized as a property of 'ion-select'

I'm encountering an issue when attempting to utilize ngModel within a modal that is a component. I have imported the FormsModule and ReactiveFormsModule into my modal / component module.ts, but the problem persists. Can someone offer assistance? Even ...

Clear drop down selections after button is pressed

I am currently working with a grid in my template that contains multiple dropdowns, each row having its own. When I click a button, I gather the values from these dropdowns. However, upon clicking this button, I wish to reset all the dropdowns back to thei ...

Files are nowhere to be found when setting up an angular project

After creating an Angular project, I noticed that some key files were missing in the initial setup, such as app.modules.ts and app-routing.modules.ts The project was generated using the command ng new name Here is a screenshot displaying all the files th ...

Ways to retrieve root context within a Vue Composition API in Vue 3.0 + TypeScript

Looking to develop a TypeScript wrapper function that can trigger toast notifications using a composition function, following the guidelines outlined in Vue 3.0's Composition API RFC. In this instance, we are utilizing BootstrapVue v2.0 for toast not ...

Even after calling ChangeDetectorRef.detectChanges, the ngOnChanges hook failed to trigger

export class AppComponent implements OnInit, OnChanges { @Input() value: number; constructor( private cdr: ChangeDetectorRef ) {} ngOnInit() { of(1).subscribe(v => { this.value = v; console.log(1); this.cdr. ...

Stop Angular (click) binding from occurring when the variable is considered 'undefined'

Currently, I am enhancing a custom Angular component by adding callbacks using the standard Angular method, like so: (click)="data.callback ? data.callback() : undefined" This approach works smoothly; when no callback is specified, Angular handl ...

Tips and tricks for setting up a functional react select component using Material UI

Having an issue with React Select material UI where the dropdown select is not functioning properly. The popup does not open up as expected. I am looking to display react select in a modal dialog box. import MenuItem from "@mui/material/MenuItem" ...

React Material UI Select component is failing to recognize scrolling event

Having some difficulty understanding how to detect a scroll event with a Select component using Material-UI. The Select has MenuProps={...}, and I want to listen for the scroll event inside it. I've tried putting onScroll within MenuProps={...}, but ...

Flatten a specific property of an object recursively

If I have a data structure containing nested objects, I need to create a type that removes specific keys and flattens certain fields recursively Input: { sys: { id: string; }; metadata: { author: string; }; fields: { ...

Utilizing the relativeTo method within a guard across various feature modules

I am facing a challenge with two lazily loaded Feature Modules that have a similar flow consisting of Select, Review, and Confirm steps. I want to create a single Guard for the Review step that can navigate back to Select based on the current Module contex ...

Tips for passing an array between components in Angular 2

My goal is to create a to-do list with multiple components. Initially, I have 2 components and plan to add more later. I will be sharing an array of tasks using the Tache class. Navbar Component import { Component } from '@angular/core'; impor ...

Transferring information between components within AngularJS

export class AppComponent { title = 'shopping-cart'; ngOnInit() { } images = [ { title: 'At the beach', url: 'https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-4.0.3&ixid=MnwxMjA ...

A guide on cycling through the data within the input fields

Here's my code snippet: <div class="form-group row text-right" *ngFor='let row of vipInput'> <label class="col-sm-3 form-control-label m-t-5" for="password-h-f"></label> <div class="col-sm-9 form-control-label m-t-5 ...

calculate the difference between two dates and then add this difference to a new date

Utilizing TypeScript for date calculations. Example: Initial Date 1: "10/06/2021 10:10:05" Initial Date 2: "08/06/2021 11:10:05" Calculate the difference between the two dates, including date/month/year/hour/min/sec/milliseconds. Ensure compatibility wi ...

After compilation, any variables declared within a module remain undefined

I have declared the following files app.types.ts /// <reference path="../../typings/tsd.d.ts"/> module App{ export var Module = "website"; //---------------Controller Base Types--------------- export interface IScope extends ng.ISco ...