styles and styleUrls not working in the default app.component.ts
styles: ['body { background-color: red }'] // should make the application's background red
styleUrls: ['app.component.css'] // should work
styleUrls: ['app.component.scss']
The application isn't styled from app.component.ts.
ng new project-name --prefix pn
ng set defaults.styleExt scss
import { Component } from '@angular/core';
@Component({
selector: 'pn-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']
})
export class AppComponent { }
@import './app.style'
body {
background-color: $bg-color;
}
$bg-color: red;
ng serve
OS: Windows 10
node: 6.3.1
[email protected]
try adding this to your @Component({ ..., encapsulation: ViewEncapsulation.None })
@PiusNyakoojo it looks like you are trying to style the body tag from inside a component. By default all angular styles are scoped to their component so that won't work.
What @deebloo said should explicitly said in the official Angular.io tutorial, it saved my day!
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
@PiusNyakoojo it looks like you are trying to style the body tag from inside a component. By default all angular styles are scoped to their component so that won't work.