How can we add the style conditionally in Angular

0 votes
With the help of code and example tell me How can we add the style conditionally in Angular?
Feb 26 in Angular by Nidhi
• 10,860 points
51 views

1 answer to this question.

0 votes

In Angular, you can add styles conditionally using [ngStyle] or [style.property].

1. Using [ngStyle] (Multiple Styles)

<p [ngStyle]="{ color: isActive ? 'green' : 'red', 'font-size': isLarge ? '20px' : '14px' }">

  Conditional Styling

</p>

2. Using [style.property] (Single Style)

<p [style.color]="isActive ? 'blue' : 'gray'">Styled Text</p>

answered Feb 26 by Tanya

Related Questions In Angular

0 votes
0 answers

How can we combine multiple built-in pipes in Angular templates?

Can you help me with a code ...READ MORE

6 days ago in Angular by Nidhi
• 10,860 points
27 views
0 votes
1 answer

How can we achieve transclusion in AngularJs?

Hii,  In order to know what transclusion is ...READ MORE

answered Feb 5, 2020 in Angular by Niroj
• 82,840 points
762 views
0 votes
1 answer

How can we reload a page after requesting the same get parameter using AngularJS?

hey kartik, The reason for this is that ...READ MORE

answered Feb 10, 2020 in Angular by Niroj
• 82,840 points
12,756 views
0 votes
1 answer

How can we provide condition based on certain resolve result obtained in routing with resolve?

Hey,  Let me consider that you have some ...READ MORE

answered Feb 11, 2020 in Angular by Niroj
• 82,840 points
2,114 views
+1 vote
8 answers

How can I implement process.env in Angular 5 environment?

Users do not have access to process.env ...READ MORE

answered Apr 3, 2018 in DevOps & Agile by DareDev
• 6,890 points
13,452 views
0 votes
1 answer
0 votes
4 answers

ReactJS vs Angular Comparison: Which is better?

Parameters React Angular Type React is a JavaScript library, and it ...READ MORE

answered Jan 7, 2021 in Events & Trending Topics by Focusteck
• 140 points
2,046 views
+4 votes
9 answers

***IMPORTANT*** AngularJS Interview Questions.

Yes, I agree with Omkar AngularJs is ...READ MORE

answered Mar 17, 2019 in Career Counselling by Sharad
• 180 points
3,940 views
0 votes
1 answer

How can structural directives manipulate the DOM in Angular?

Structural directives in Angular (*ngIf, *ngFor, *ngSwitch) ...READ MORE

answered Feb 26 in Angular by Navya
40 views
0 votes
1 answer

Can we create a custom directive in Angular?

You can create a custom directive in ...READ MORE

answered Feb 26 in Angular by Tanya
35 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP