1

I made a header component in order to keep my header consistent throughout the website so that I dont have to write the header code repeatedly. On placing the selector in the index.html file, I couldn't see the result. Please tell the correct way to do that

index.html file

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>stuff</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
    <app-header></app-header>
    <app-root></app-root>


</body>

</html>

i just have a paragraph tag saying 'header works' in my headerComponent and it is all generated by angular-cli, no modifications made.

1 Answer 1

2

Put it in the app.component.html above <router-outlet> </router-outlet> tag as:-

<div> <app-header></app-header> </div> <router-outlet> </router-outlet>

Sign up to request clarification or add additional context in comments.

3 Comments

can't it be used in index.html directly?
I guess No because at the time index.html is rendered it has no information about <app-header> as <app-root> is the starting point of the application.
this will solve the purpose i.e. header consistent throughout the website.

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.