当前位置: 首页 > 工具软件 > angular-cli > 使用案例 >

Angular-cli

劳和雅
2023-12-01

    如果纯手工搭建Angular 2.0的项目结构,会有点复杂,一般我们需要使用一些脚手架,比如Angular-cli。

    1.安装Angular-cli

     使用npm安装:

npm install angular-cli -g
      2.新建一个Angular 2.0的基本项目

ng new Project_Name

     3.运行Angular 2.0项目

cd Project_Name
ng serve
    在浏览器访问http://localhost:4200,就可以看到项目运行了。

    4.新增组件

    项目运行了,但该项目只是一个具有基本结构的项目,我们可能需要开发额外的component。

ng g component Componeng_Name
    运行改命令后,就会在app文件夹下面生成一个对应的文件夹。并且项目根模块中也增加了组件的相应配置。

    5.其他

    处理新增组件外,还可以新增别的

ng g service Service_name      //新增服务
ng g directive Directive_name //新增指令
ng g module Module_name    //新增模块
ng g pipe Pipe_name             //新增管道



    

 类似资料: