我目前正在学习Angular,想知道应该在index.html和app.component.html中确切编码什么,而不是在组件中编码。
我当前的Angular项目是我的个人网站,我想迁移到Angular进行培训。您可以在http://www.chloe-seiler.com/
上找到它-没关系,正在努力。-
基本上有一个标题,一个导航栏和一个正文。正文仅在导航时有所不同,标题和导航保留在整个网站中。
我应该在index.html中编码标题和新标题吗?还是在app.component.html中?还是应该让它们成为组件,在这种情况下:index.html和app.component.html是否保留为空?
预先感谢您的帮助!
答案 0 :(得分:1)
index.html :就正在开发诸如个人网站之类的基本应用程序而言,index.html可用于包含css,js,图标,字体和设置标题,并放入用户定义的脚本。
app.component.html :这将保存应用程序级组件的组件视图。现在的一个好习惯是在应用程序中为每个组件使用路由。然后,您只需输入
<router-outlet></router-outlet>
标签显示您的布线组件。 Here is a simple example of routing.如果您不使用多个组件,则只能使用app.component.html来显示应用程序级别的组件。
答案 1 :(得分:0)
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