我应该在 Angular index 和 app.component.html 中写什么?

Chl*_*loé 9 html architecture components web-applications angular

我目前正在学习 Angular 并想知道究竟应该在 index.html 和 app.component.html 中编码什么 - 而不是在 components 中编码。

我目前的 Angular 项目是我的个人网站,我想将其迁移到 Angular 以进行培训。您可以在http://www.chloe-seiler.com/ 上找到它

-不管响应度,我正在努力。-

基本上有一个标题,一个导航和一个正文。正文仅在导航时不同,标题和导航在整个网站中保留。

我应该在 index.html 中对 header 和 new 进行编码吗?还是在 app.component.html 中?或者我应该让它们成为组件,在这种情况下:我的 index.html 和我的 app.component.html 是否保持为空?

在此先感谢您的帮助!

Yas*_*han 8

index.html:就开发个人网站等基础应用而言,index.html可以用来包含css、js、icon、字体和设置标题,放入用户定义的脚本。

app.component.html:这应保存应用程序级组件的组件视图。现在,一个好的做法是在应用程序中为每个组件使用路由。然后你可以只输入

<router-outlet></router-outlet> 
Run Code Online (Sandbox Code Playgroud)

标签来显示您的路由组件。这是一个简单的路由示例。如果您不使用多个组件,则可以仅使用 app.component.html 来显示应用程序级组件。


Ayo*_*b k 2

app/app.component.ts - 这是我们定义根组件的地方
index.html - 这是组件将在其中呈现的页面

所以index.html它只是一个起始页面,您可以添加到全局CSS的链接和全局页面标题....

app/app.component.ts 和她的模板文件 (app/app.component.ts) 每次路由更改时都会被调用......所以页眉和页脚应该在其中:

<app-header></app-header> // here's goes the header
<router-outlet></router-outlet> // here's goes the content of each route
<app-footer></app-footer> // here's goes the footer
Run Code Online (Sandbox Code Playgroud)