Got home component with background-color:red written into its scss and then got user component with background-color:green written into its scss. I start my app, I am at home, got red background, go to user page, got green background. Works like it should...but now when I go back my home component background is still green. All components have ViewEncapsulation.None.
If I start navigation from user page, same things happen, but background colors vica-vera.
I always understood that point of component style is to affect only its component and not others. Is it not how that supposed to work?
Edit: If I set ViewEncapsulation.Emulated I see no styling from component style scss file being applied, so both pages are having white background.
This is how my home component file looks:
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
encapsulation: ViewEncapsulation.Emulated,
})
export class HomeComponent implements OnInit {
ngOnInit() {
}
}
Edit: You see my problem was that I was setting background color for <body>, but the body aint part of the template, this why encapsulation: ViewEncapsulation.Emulated and component stylesheets aint affecting it.
ViewEncapsulation.Noneliterally means "don't isolate view css" - Benjamin Gruenbaumbodywithout even bothering about view encapsulation. If your style collide, encapsulate. if your style aren't getting applied, check the variable names. Finally, if you don't know how to style the body using Angular, please provide a minimal reproducible example so that we can show you how to. - user4676340