Tag <head> <body> in Angular projects

Asked

Viewed 94 times

2

I’m studying Angular and I was left with a ref doubt. the use of tags <head> and <body>

For example, in an html file would:

<head>
    <title>{{ tittle }}</title>
</head>
<body>
        <p>teste</p>
</body>

Would need the use of these tags in angular projects?

  • I don’t know where you are learning and what level of learning you are at, but when you create an Angular project, the only HTML file that will have the tags head and body is the index.html inside the default folder src. It basically serves to index the application in the browser, but for development purposes it is practically not used.

  • Leandrade, when creating a new Component using the angular cli tool, a new file is automatically created. html, my doubt is, there is need to include these tags in these new files?

  • No need not

1 answer

3


When you create an Angular project, by default inside the folder src has a file called index.html. This file basically contains the structure you quoted, head, body and some other items. This file will be delivered every time your browser accesses your application.

Inside this file there is another important tag, usually called app-root (can be changed) which is where Angular will create all the visuals and will manage (create DOM, add events, etc.) the entire application on the client side using Javascript.

So how will your application deliver a single file with the basic structure of an HTML page, for example to change the title, you will have to resort to the functions that Angular has. To make this change to title you will have to resort to class Title in @angular/platform-browser.

So you don’t have to worry so much about the head and body since they will be in a single file. My suggestion is to worry about how Angular works: https://angular.io/guide/architecture

Browser other questions tagged

You are not signed in. Login or sign up in order to post.