前端三大框架的angular 的安装和初始化
angular 和vue、react一样得先安装node,因为需要使用到npm和一些node包的使用
node的安装我就不说了
angular他推荐使用的就是typescript(ts),我们就使用ts进行编写
1 | npm install -g typescript //安装ts |
创建个项目和大多数的创建项目差不多
1 | ng new demo//ng new 项目名字 |
安装好进入demo 运行
1 | cd demo |
运行后会在4200的端口查看你的页面
我们看下结构demo里有
1 | src |
单元测试看这
创建组件
1 | ng generate component stock/stock-item //文件夹和文件 |
*.component.html 组件模板
*.component.ts 组件的定义
*.component.css 组件的样式
*.component.spec.ts 组件单元测试脚手架
创建这些文件的同时会在app.module.ts里加入引入
在app.component.html文件里写上就可以使用了
1 | <app-stock-item></app-stock-item> |