一、创建组件

1.创建一个 news组件
ng g component [组件目录/组件名称]

ng g component components/news

Angular:创建使用组件(二)
2.在VS Code中查看项目结构
Angular:创建使用组件(二)
3.如果通过命令行创建组件,将自动在 app.module.ts 中引入
Angular:创建使用组件(二)

二、使用组件

1.在 app.component.html 中添加 news 组件

<!--The content below is only a placeholder and can be replaced.-->
    <app-news></app-news>

2.在 news.component.html 中添加内容

<h1>新闻组件</h1>

3.运行项目

ng serve --open

Angular:创建使用组件(二)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-12-19
  • 2021-07-27
  • 2021-08-15
  • 2021-12-30
  • 2022-12-23
猜你喜欢
  • 2021-05-22
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
相关资源
相似解决方案