两种创建方式:手动创建和命令创建
手动创建:
一:基础知识:
代码说明:
二:代码实现:
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组键即可
--------------------- 本文来自 七刀 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/u011321546/article/details/80739636?utm_source=copy