两种创建方式:手动创建和命令创建
手动创建:
一:基础知识:


代码说明:

二:代码实现:
1.在app目录中新建组键目录和文件

2.ts文件中添加修饰器和引入模板

-
import {Component} from '@angular/core'; -
@Component({ -
selector: 'app-server', -
templateUrl: './server.component.html' -
}) -
export class ServerComponent { -
}
3. html文件中添加内容

-
<!DOCTYPE html> -
<html lang="en"> -
<head> -
<meta charset="UTF-8"> -
<title>Title</title> -
</head> -
<body> -
<p>这是一个server主键</p> -
</body> -
</html>
4. 在文件app.modul.ts中添加server组键

5. 在文件app.componert.html中引用server组键

显示如下:

命令创建:
一:Alt+F12 打开命令模式,输入 ng generate component servers
或者缩写 ng g c servers
指定创建组键servers
自动创建组建目录和文件,并自动在modul中添加


二: 在文件app.componert.html中引用servers组键即可

--------------------- 本文来自 七刀 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/u011321546/article/details/80739636?utm_source=copy
本文详细介绍了在Angular项目中创建组件的两种方式:手动创建和使用命令行工具。手动创建涉及编辑ts文件,添加修饰器,引入模板,以及在html文件中添加内容。命令创建则通过Alt+F12打开命令模式,输入特定命令自动完成组件创建。
1406

被折叠的 条评论
为什么被折叠?



