4

I am new to angular and build two component in my first angular app. In first component i put a click on button to navigate to second component.

I m using below code for navigation :

this.router.navigate(['../secondcomponent/'], { relativeTo: this.route });

but i can see that second component is having css of component 1. How can i make sure that on each router navigation previous component css will removed and only that component as well as the index.html css should be present?

Feroz Siddiqui
  • 3,840
  • 6
  • 34
  • 69

1 Answers1

3

Your components should be encapsulated : this means that if you declare CSS of a component, it is only for that component.

If this isn't the case, you either :

  • declared your styles into a common CSS file
  • declared a CSS file as a stylesheet of both components
  • Un-encapsulated your components

In all cases, resolving it will resolve your issue. Could you post your code so that we can see what you did ?