首页 > 解决方案 > 新组件未呈现 Angular

问题描述

我是 Angular 的初学者。我想在我的项目中创建一个新组件,但是当我在 index.html 中使用它时它没有呈现。

我使用了这个命令:

ng new test
cd test
ng generate component radio

在我编辑了我的 index.html 之后:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>test</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root>Loading...</app-root>
  <app-radio>Loading...</app-radio>
</body>
</html>

我做的结果ng serve

 app works!
 Loading...

在 app/radio/radio.component.html 我有这个代码自动生成:

<p>
  radio works!
</p>

那么,为什么它不在我的浏览器中呈现?我的错误在哪里?

标签: javascriptangularangular-cli

解决方案


您的 app-root 是您的 Angular 应用程序的应用程序容器。

<app-radio></app-radio>在 app.component.html 中设置您的内容,您应该会看到它。

希望有帮助!


推荐阅读