How to use styleurls and styles in angular 2?



How to use styleurls and styles in angular 2?..

Answer / A. Vinoth Saravanan

In Angular 2, you can define CSS using the `styles` property for inline styles or the `styleUrls` property for external stylesheets. To use them, follow these steps:

1. Declare the component and add the styles or styleUrls:

```typescript
import { Component } from '@angular/core';

@Component({
selector: 'my-app',
template: `<h1>Hello World!</h1>`,
styles: [`h1 { color: red; }`],
styleUrls: ['styles.css']
})
export class AppComponent {}
```

2. Create the external CSS file (styles.css) and define your styles there.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

What is nginclude?

1 Answers  


What are constructors in angular?

1 Answers  


What is provider?

1 Answers  


Is angular a oop?

1 Answers  


How can someone make an ajax call using angularjs?

1 Answers  


What happens when the page containing angular based application loads?

1 Answers  


what is the difference between a module’s forroot() and forchild() methods and why do you need it?

1 Answers  


Explain factory method in angularjs?

1 Answers  


What is a template in angular7?

1 Answers  


What does a router.navigate do?

1 Answers  


What are http interceptors?

1 Answers  


How did we work with multiple modules in our project?

1 Answers  


Categories