angular CLI 实践

这里写图片描述
这里写图片描述

测试是否安装成功:ng version

官方版安装命令

这里写图片描述

注:使用cnpm从国内地址下载依赖包,大大提高了下载速度,节省时间。所以通常会使用下面的命令安装cli

这里写图片描述

创建 项目demo01的目录,注意此时在文件夹内还没有创建文件,知识创建了目录结构。
ng new demo01 -d

(友情小提示: 使用new help 查看所有的命令,帮助提高你的开发效率哟~)

这里写图片描述

使用ng new demo01 -si –routing 创建路由模块,此时项目文件夹里已经有项目了哦~~
这里写图片描述

启动项目
使用ng serve 命令启动项目
这里写图片描述

浏览器显示app.compontent.html中的内容
这里写图片描述

app.compontent.html
这里写图片描述

app.component.ts
这里写图片描述

默认的启动端口是http://location:4200,有些情况下,我们可能会运行多个项目,此时可以通过ng serve –port XXXX 的命令来改变默认的端口号。

这里写图片描述

这里写图片描述
使用 ng g compomtent xxxx 创建组件,g是 generate的简写

这里写图片描述

App.module.ts中update的内容
这里写图片描述

子组件中的Test.component.ts中的 selector:’app-test’ 表示类选择器,可以嵌套到父组件app.component.html中
这里写图片描述

app.component.html
这里写图片描述

浏览器显示
这里写图片描述

创建serveice
这里写图片描述

创建 ng generate == ng g
创建组件 ng g component componentName
创建服务 ng g service serviceName
-m:将service注册到app module里面去

学习参考:
https://www.imooc.com/video/15152
https://cloud.tencent.com/developer/article/1069200

猜你喜欢

转载自blog.csdn.net/duyusean/article/details/80301095
今日推荐