1.安装 nodejs(最新稳定版)https://nodejs.org/en/
安装 typescript
npm install -g typescript
安装 angular-cli(关于CLI的使用方法可以看这里 https://cli.angular.io/ )
npm install -g angular-cli
(此处安装失败的话,可尝试将 nodejs 升级到 LTS 版)
2.安装好 angular-cli,就可以使用 ng 命令创建项目了
ng new [Project Name]
3.进入项目并启动
cd [Project Name] ng serve
尝试运行 http://localhost:4200 (默认是端口 4200)
自定义端口:
ng serve --port 4201
自定义IP:
ng serve --host 192.168.1.151
4.创建新组件
ng generate component simple-form --inline-template --inline-style
可缩写为:
ng g c simple-form -it -is
5.了解项目结构
看一下,app.module.ts,自动关联组件文件 simple-form ,新建的组件位置在 src/app/simple-form
看一下,app.component.ts 引用结构,在 app.component.html 中 加入
<app-simple-form></app-simple-form>