【问题标题】:What should I write in Angular index and app.component.html?我应该在 Angular 索引和 app.component.html 中写什么?
【发布时间】:2019-01-31 18:27:58
【问题描述】:

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

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

-别管响应性,我正在努力。-

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

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

提前感谢您的帮助!

【问题讨论】:

    标签: html angular web-applications architecture components


    【解决方案1】:

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

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

    <router-outlet></router-outlet> 
    

    标签来显示你的路由组件。 Here is a simple example of routing. 如果你不使用多个组件,你可以只使用 app.component.html 来显示应用级组件。

    【讨论】:

      【解决方案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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-25
        • 1970-01-01
        • 1970-01-01
        • 2012-09-22
        相关资源
        最近更新 更多