how to include an external css in angular 4?



how to include an external css in angular 4?..

Answer / Rita Kumari

To include an external CSS file in Angular 4, you can use the following steps:
1. Place your CSS file in the 'assets' folder.
2. Import the CSS file in your component by adding `import './path/to/your/css-file.css';` at the top of your component.
3. In your component's constructor, add `this.constructor();` and call a function to initialize styles:n```typescriptnngOnInit() {n this.initializeStyles();n}nprivate initializeStyles() {n if (window.getComputedStyle(document.body).getPropertyValue('--primary-color') === null) {n document.documentElement.style.setProperty('--primary-color', 'blue');n }n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

Explain $templatecache in angularjs?

1 Answers  


What is the difference between routermodule.forroot() vs routermodule.forchild()?

1 Answers  


Is typescript an oop?

1 Answers  


What is cdk in angular?

1 Answers  


Explain .config() and .run() methods in angularjs?

1 Answers  


What is a directive question?

1 Answers  


What is ng build command?

1 Answers  


What is difference between javascript and typescript?

1 Answers  


What is typescript in Angular 8?

1 Answers  


What classes should I not add to module's declarations?

1 Answers  


What is templateref and viewcontainerref?

1 Answers  


Explain the process how do we exchange the data from front end to server?

1 Answers  


Categories