2

How to import css based on condition like below,

Angular7

In styles.css

if (data === 'mobile') {
  @import './assets/css/common1.css'; 
} else {
  @import './assets/css/common2.css'; 
}

My problem is:

I have two modules which loads different application in my project.

{
  path : ''
  loadChildren: Module1
}

{
  path : 'ng7'
  loadChildren: Module2
}

Here, I want to use Module 1 - common1.css and Module 2 - common2.css

6
  • try stackoverflow.com/questions/42824472/… Commented Nov 10, 2018 at 16:20
  • 1
    Possible duplicate of angular2: how to manually add css files by condition to index.html? Commented Nov 10, 2018 at 16:25
  • No Alok Deshwal. I tried . But my problem is to add only one css based on condition. Commented Nov 10, 2018 at 16:26
  • Sceanrio: module1 need to load common1.css and module2 need to load common2.css. These 2 different application in my project Commented Nov 10, 2018 at 16:28
  • If you are loading the modules dynamically, then add css files using "styleUrls" to the associated components of module. Commented Nov 10, 2018 at 17:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.