创建组件
ng
命令生成组件会自动引入我们所创建的新组件中。建议ng
命令作为创建组件的首选。
在src/app/components/
创建一个twoer
组件
命令:
ng generate component <name> [options]
ng g c <name> [options] (简写)
常用的options:
--export=true|false //true,将exports(导出)这个组件
--inlineStyle=true|false //样式是否为内联形式
--inlineTemplate=true|false //模板文件(html)是否为内联形式
--skipTests=true|false //是否安装单元测试文件
// cd 到项目根目录执行命令:
ng g c component/twoer
将在src/app
下面自动生成components/twoer
文件夹,里面包含四个文件:
twoer.component.html
twoer.component.css
twoer.component.ts
twoer.component.spec.ts
并且在src/app/app.module.ts
中自动引入了twoer
组件
调用组件
// app.component.html
<app-dialog></app-dialog>