依赖
- Node 6.9.0 or higher
- Python
- C++ 编译工具
安装
初始化项目
启动开发服务
ng serve
ng serve
默认占用 4200
端口号,可以通过下面选项配置:
# 创建组件
ng generate component my-new-component
# 创建组件别名
ng g component my-new-component # using the alias
# components support relative path generation
# if in the directory src/app/feature/ and you run
# your component will be generated in src/app/feature/new-cmp
ng g component ../newer-cmp
# your component will be generated in src/app/newer-cmp
# if in the directory src/app you can also run
ng g component feature/new-cmp
# and your component will be generated in src/app/feature/new-cmp
可辅助创建资源的功能列表:
angular-cli will add reference to components
, directives
and pipes
automatically in the app.module.ts
. If you need to add this references to another custom module, follow this steps:
ng g module new-module
to create a new module- call
ng g component new-module/new-component
This should add the new component
, directive
or pipe
reference to the new-module
you’ve created.
在脚手架项目中使用 SASS 预处理器
如果想要在脚手架项目中使用 SASS 预处理器,我们需要自己手动修改一些配置文件,请按照以下步骤依次修改:
- angular-cli.json 里面的 styles.css 后缀改成
.scss
当你后面再使用 ng g c ***
自动创建组件的时候,默认就会生成 .scss
后缀的样式文件了。
- angular-cli.json 里面的 styleExt 改成 .scss
- src 下面 styles.css 改成 styles.scss
- app.component.ts 里面对应修改
改完之后,重新 ,打开浏览器查看效果。
SASS 的 API 请参考官方网站 。