0

I'm working on a project using angular 4, How do I add class to the body of index.html only. for example

   <body class="home">
      <app-root></app-root>

   </body>

I want this class to be added only when my HomeComponent load and remove for any other pages/component

Cheers to everyone.

0

1 Answer 1

3

You can't really use Angular features in the index.html. I would suggest a different approach to the structure of your application.

Define your app-root component to only be a router-outlet. Then build a shell component with your menu, header, and any other styles you want for your "home".

You can then route any pages you want without the styles directly into the app-root's router-outlet and any pages you want with your style to the shell component.

I have an example set up this way here: https://github.com/DeborahK/MovieHunter-routing

app.component.html

<router-outlet></router-outlet>

shell.component.html

<mh-menu></mh-menu>

<div class='container'>
    <router-outlet></router-outlet>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.