60 questions
0
votes
3
answers
847
views
ngClass does not switch value when using object in component
When I use the following code to switch the class everything works fine
<p [ngClass]="idPresent ? 'alert alert-success' : 'alert alert-danger'">
Working
</p>
On changing the ...
0
votes
0
answers
26
views
bug situation with Angular_Ng0303 *ngFor
I,ve been some days I started learning Angular, and now I'm having some troubles (here's the problem) when calling to the *ngForOf directive in a li, can someone help me?
pd: In the trouble picture, ...
1
vote
3
answers
80
views
How to add condition and function both in ngClass?
I need to use both function and condition in ngClass like below:
<div [ngClass] = "i==1 ? 'active':'inactive',getclass()">
</div
TS
getclass(){
return 'myclassname'
}
1
vote
1
answer
486
views
ngClass not detecting the changes when current item related to array change
iam listing some images from an array,the current image has a orage border.
when the user clicks an image it becomes the current image
but on clicking the border from previous current image ...
0
votes
0
answers
758
views
Facing issue in adding style to ng-container for only inside a div
I am trying to mimic the behavior of mat-form-field for required validation on ng-select
In order to mimic the behaviour I need to add border and color as red when mat-error trigeered.
Here is my HTML
...
0
votes
2
answers
2k
views
How can I apply pseudo class by condition in Angular?
I have the following css
#auction-history div:after {
content: "";
width: 100%;
height: 8px;
position: absolute;
bottom: -8px;
background: #bad3e0;
left: 0;
}
...
-1
votes
2
answers
649
views
How can we write two ngClass in one div? [duplicate]
Can we add two ng-class in one div?
If so then how to write it.
How can we write this together?
Thank you in advance.
<div [ngClass]={'white-background': policy number.length <=0}
[ngClass]=&...
1
vote
2
answers
3k
views
Angular6 Can't use ternary operator in ngClass with multiple entries
I'm trying to add multiple classes by ngClass, and I'm confused as to why I can't use ternary operator here.
<div [ngClass]="{'otherClass': otherFlag, classFlag ? 'class--true': 'class--false'}...
0
votes
1
answer
88
views
angular - how to combine few ngclass together in one div
I would like to combine multiple ngClass if else statement together, I have tried but not able to resolve it.
<div
[ngClass]="[tabItem === 'unavailable' ? 'background-grey' : selected ? '...
0
votes
4
answers
1k
views
How to use a function and expression in a ngClass using Angular?
I'm currently trying to show a list of Pokemons that have a different background color depending on their type. I would like to implement a feature where the border of the selected pokemon also shows ...
0
votes
1
answer
798
views
Angular 11 - text-decoration: line-through does not work properly with class binding
So I am making a todo app and I want to add stroke to the done tasks but the problem is that it is not working properly.
my .css file
.stroke{
text-decoration: line-through
}
and the element in ...
2
votes
2
answers
479
views
Efficiently apply [ngClass] expression against td
I am loading a dynamic table from a JSON file and on td i am using an angular expression to evaluate the css class name based on some application logics
The HTML and TS code is like below
<td *...
1
vote
2
answers
710
views
routerLinkActive id coupled with [ngClass]
Below web-link demonstrates the routerLinkActive id working when used as a boolean value for a distinct HTML element' [ngClass]
https://stackblitz.com/edit/routerlinkactivesimple?file=src%2Fapp%2Fapp....
-1
votes
2
answers
836
views
Angular : how to toggle selection between children components
So I have got a parent component with children components binded over an ngFor()such as:
<categories *ngFor= "let category of categories" [category]="category"></...
0
votes
0
answers
893
views
Angular Material Table Apply Class based on [dataSource]
I have built an Angular Material Table and would like to use class error-text if the [dataSource] returns isActive=false.
I'm trying to do this with no luck:
<table
mat-table
[dataSource]="...
1
vote
2
answers
1k
views
Which way has the best performance applying several classes to html tags? Angular 2
I am building a calendar with prices, I have 3 nested elements:
- calendar-layout
-- calendar-month
--- calendar-week
In the calendar-week I have to do several calculations for the different styles ...
0
votes
1
answer
873
views
How can I assign different colors to disabled columns in Mat-Table?
i have disabled several columns in my table and want to display them in different colors. Therefore I wrote a function in Typescript where CSS is changed via the class .disabledRange. I have read that ...
0
votes
1
answer
841
views
how to show spinner for selected table row in angular 8
I have a list of videos coming from api. when play icon of a particular video from table is clicked a modal box opens.
I want that when we submit this modal box a spinner starts rotating until it get ...
8
votes
2
answers
10k
views
How to add CSS class name from variable in Angular 9 depends on boolean variable?
I want to add class names from a variable, but it's depends on another variable in Angular 9.
Here is my TypeScript code
export class InputComponent implements OnInit {
@Input() inputBlockClass = '...
1
vote
5
answers
685
views
ngClass directive to use with ngFor
I have some list elements, which I am rendering using *ngFor directive. However, some part of the list items text should be bold according to the specs. I tried to do this with the [ngClass]="'strong'"...
0
votes
2
answers
105
views
Regex to split a long expressions string into an array of individual expressions
I have an expression string from Angular [ngClass] directive containing multiple expressions with their corresponding key separated by a comma.
'background_orange':row.columnname.split(',')[4] == 1,'...
2
votes
2
answers
100
views
How to avoid repetitions within Angular ngClass?
Imagine following situation:
<div *ngFor="let d of dm; first as first">
<span
[ngClass]="{ cSmall: !first, cGray: !first, cTab1: !first }"
>
{{ d }}
</span>
...
2
votes
2
answers
69
views
ng-class issue with condition in angular?
I have two link which is displaying two different images on click of respective link.first behaviour is fine but when again I click on selected link, image is displaying correct but hover is moving to ...
0
votes
2
answers
3k
views
How to highlight only one expansion panel onclick and reset if choose other
Firstly, I am very new to Angular world. Trying to achieve a task. I really appreciate all inputs. Coming to the issue.
I am creating multiple expansion panel using a "ngFor". I want to highlight or ...
1
vote
2
answers
6k
views
Button color change based on condition in ngclass in Angular6
If i click the button it will change the color in to orange but by requirement is after click the same button it need to change into default color. so please guid me to do this.
<button #val1 ...
2
votes
2
answers
1k
views
Angular: Errors with passed @Input values to override button text and add class by using ngClass
I've created an angular component called app-button.
The template looks like this:
<div class="app-button">
<button class="app-button__btn">{{text}}</button>
</div>
In ...
-1
votes
3
answers
2k
views
The ngclass is not working as expected in angular 6
I am trying to change the value of [ngclass] field based on the values present in array but it is not working as expected.
The html code is as below:
<ul>
<li [ngClass]="{...
10
votes
2
answers
4k
views
ExpressionChangedAfterItHasBeenCheckedError with ngClass
I have two anchor tags
<ul class="switchNav">
<li [ngClass]="!hidePanel2 ? 'active' : ''">
<a href="javascript:void(0)" (click) ="hideShowPanel(1)">panel 1<...
1
vote
3
answers
217
views
ngClass wrong answer
After going through a lot of questions , I have decided to ask this...
The angular [ngClass] is working weird on the values for 10 , 24 , 100 . I don't know the reason behind it . Hoping you could all ...
-1
votes
1
answer
222
views
How to add a class to a specific selected li element in *ngFor
I have the following html snippets
<ul>
<li *ngFor="let report of searchResult.reports let i = index;">
<input type="checkbox" [(ngModel)]="report.reportChecked" (click)="...
1
vote
0
answers
49
views
Delaying display of page until [ngClass] has been evaluated
Background I have a header component having [ngClass] attached to top div.
Question Is it possible to delay displaying of page until [ngClass] has been evaluated? We used to have ng-cloak in ...
0
votes
1
answer
2k
views
Using Angular ngClass dynamically not working
I am trying to dynamically set the class of my image in my template depending on which image is clicked. I have used this precisely as shown in the past and it worked then but is not working in this ...
0
votes
1
answer
896
views
ngClass Is Loading Only One Class Out of a String of Classes
I am using ngClass (Angular 2) to load a string of classes if condition is true and other string of classes if the condition is false!
Here is the code:
<label [ngClass]="{'btn btn-success m-btn ...
1
vote
0
answers
836
views
ngClass style not being applied
I have a component with a TS file that has this section in it:
@Component({
selector: 'nav-menu',
templateUrl: './navmenu.component.html',
styleUrls: ['./navmenu.component.scss']
})
I ...
0
votes
0
answers
693
views
Angular 5 [ngClass] to change language settings
The following static html <ul> dropdown (with style included below) works perfectly.
Now I'm trying to convert this to an Angular 5 dynamic <li> using *ngFor* and ngClass .
<!-- ...
0
votes
2
answers
964
views
add ngClass to all the divs clicked
I'm trying to add 'active' class to all the divs (options in this case) that are clicked and remove the class on a second click.
The options count can vary as it's generated by ngFor.
HTML
<div [...
1
vote
8
answers
27k
views
Add and Remove class in Angular
I want to add background color to the li element when clicked but when I clicked another li element the previous li element background color remains unchanged.
component.html
<div class="col-md-...
-1
votes
1
answer
3k
views
Angular Built-in Directives are not working(ngClass, ngStyle, ngIf)
I am following Template syntax section for the application of built-in attribute and structural directives from here https://v4.angular.io/guide/template-syntax#ngclass
currentClasses: {};
...
0
votes
1
answer
4k
views
how to show/hide dynamic id of div's in angular2
Here a loop of kpiName is executed and inside loops of subRegion also executed.
As a result 4 divs of class="col-xs-2" are created and inside it two div(clickable divs inside filter class) are created ...
0
votes
1
answer
632
views
ngFor First and Last Instance of a Class Do This
I am using Angular 4+. Please note: first and last needs to be based on the class instance, not the element. So a let first = first in the ngFor will not work. I currently imported jQuery to handle ...
3
votes
2
answers
7k
views
Change Width of Layout in A Certain Component in Angular
Is it possible that you change the width of your layout in a selected component only? I wanted to change the <div class="page home-page"> only in my login component? Only in login component and ...
1
vote
2
answers
2k
views
How to remove ngClass while widening the screen
I am adding a class to 2 div to toggle sidebar header using [ngClass] how do i remove those class when enlarge the screen.
The problem is on widening the screen it remains there only because class is ...
104
votes
9
answers
86k
views
Difference between [ngClass] vs [class] binding
What is the difference in Angular 2 between the following snippets:
<div [class.extra-sparkle]="isDelightful">
<div [ngClass]="{'extra-sparkle': isDelightful}">
3
votes
1
answer
1k
views
Angular2 [ngClass] Conditional fails with Spaces
I have an ngClass conditional that functions fine on class names without spaces, but when i try to do something like below and i toggle isTrue on button click, the class changes from "btn btn-primary" ...
90
votes
9
answers
313k
views
Angular ngClass and click event for toggling class
In Angular, I would like to use ngClass and click event to toggle class. I looked through online but some are angular1 and there isn't any clear instruction or example. Any help will be much ...
-2
votes
2
answers
4k
views
ngClass in Angular not applied
I am trying to use [ngClass] in Angular and seems like it is not getting applied. Surprising [ngStyle] for similar css styles are working. Waht am I doing wrong here? There is no error in the console. ...
3
votes
1
answer
11k
views
ngClass is not working in angular 4
ngClass directive generating the following error
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'li'.
code snippet.
<...
0
votes
1
answer
59
views
Why does my ng-class display even when false
I have an image I'm trying to shake when a user guesses the name of a fish wrong. I'm using a conditional ng-class="{'shake':error}". However, even when the answer is correct the image shakes. I don't ...
0
votes
2
answers
951
views
Toggle two classes with AngularJS / jqLite on click
I wan't to get a slideIn / slideOut animation by toggling the classes slideInRight and slideOutRight to a ul element.
I've tried it in different ways but I it only works with one className.
How ...
1
vote
3
answers
6k
views
how to apply border color for ion-card using ngClass
i an array like below
this.defaultBackground=[{"applyBackground":"true"},{"applyBackground":"false"}];
in my html i have used ion-card
<div *ngFor="let details of addressArray; let idx = index"
...