【问题标题】:how do i display a different page using the browser?如何使用浏览器显示不同的页面?
【发布时间】:2020-05-29 03:05:26
【问题描述】:

Angular 新手。我注意到默认情况下,当我们第一次创建 Angular 项目并在 localhost:4200/ 上查看时会显示 app.component.html 我在一个教程中了解到,为了制作另一个页面,让我们说一个类似于 instagram 如何探索页面的“探索页面”,我会将页面创建为一个组件。

我的问题是,既然我创建了探索页面组件,我将如何在浏览器上显示该站点? 无需使用路由或不必先通过初始页面

【问题讨论】:

  • 您希望它不是 app.component 显示为第一页,而是您希望它是 explore-page.component 吗?
  • @jeffreyrampineda 是的。 explore-page.component.html 有一个完整页面的代码。我想看到这个探索页面而不是 index.html。
  • 您可以转到 app/ 文件夹外的 index.html 文件,并将 选择器替换为 选择器。见底部答案

标签: angular


【解决方案1】:

不使用路由,如果要显示一个组件,可以使用它的选择器

示例:

// src/app/app.component.html
<app-explore-page></app-explore-page>

// src/index.html
...
<body>
    <app-explore-page></app-explore-page>
</body>

// src/app/app.module.ts
...
bootstrap: [ExplorerPageComponent]

【讨论】:

    猜你喜欢
    • 2012-12-17
    • 2015-04-22
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多