博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Angular CLI简介2
阅读量:4288 次
发布时间:2019-05-27

本文共 1887 字,大约阅读时间需要 6 分钟。

本文整理 Angular CLI的常用命令

我们在使用Angular2项目时,直接使用官网提供的基础配置文件,在NodeJS下面就可以生成一个新的ng2项目,但是这样非常不便利,每次都要新建目录,复制配置文件,使用Node命令安装支持库,最后才是写代码。Angular-cli就是用来简化这一操作的,而且官方配置文件不包含打包命令,对于新手来说,对System打包和webpack打包都不熟悉的情况下,使用Angular-cli能够非常方便的生存一样ng2项目,打包ng2项目,集中在编写项目代码上,省略繁琐的配置过程。

1、 安装Angular Cli

npm install -g angular-cli

-g命令表示安装在全局。

2、使用Angular cli初始化ng2项目

ng new my-ng2-app

这样就创建一个名为my-ng2-app的项目

如果在要把现有目录转成ng2项目,只需要运行下面命令:

mkdir ng2-testcd ng2-testng init

3、运行ng项目

ng serve

或者

npm start

两个都可以,默认端口为:4200

4、修改默认端口 -> 修改为(3000)

ng serve -p 3000

5、打包发布

ng build

目录中就会出现dist文件夹,可以看到里面就是打包后的文件,包含一些html、js等文件,上传服务器就可以运行代码了。

6、修改文件

修改目录中的src文件夹,里面就是TypeScript书写的组件,服务,管道,指令等文件。

二、使用ng g / ng generate  命令创建文件

ng generate component my-new-componentng g component my-new-component # using the alias# components support relative path generation# if in the directory src/app/feature/ and you runng g component new-cmp# your component will be generated in src/app/feature/new-cmp# but if you were to runng g component ../newer-cmp# your component will be generated in src/app/newer-cmp# if in the directory src/app you can also runng g component feature/new-cmp# and your component will be generated in src/app/feature/new-cmp

You can find all possible blueprints in the table below:

Scaffold Usage
ng g component my-new-component
ng g directive my-new-directive
ng g pipe my-new-pipe
ng g service my-new-service
ng g class my-new-class
ng g guard my-new-guard
ng g interface my-new-interface
ng g enum my-new-enum
ng g module my-module

angular-cli will add reference to componentsdirectives and pipes automatically in the app.module.ts. If you need to add this references to another custom module, follow this steps:

  1. ng g module new-module to create a new module
  2. call ng g component new-module/new-component

This should add the new componentdirective or pipe reference to the new-module you've created.

更多:

转载地址:http://bxogi.baihongyu.com/

你可能感兴趣的文章
【Win7系统 沙滩啤酒桌面主题】
查看>>
【.NET支持上下左右移动操作】
查看>>
【用Win7备份与还原让系统轻松回魂】
查看>>
【用Win7自带的DVD Maker制作视频】
查看>>
【幸福相守Windows7桌面热门主题】
查看>>
【天天酷跑新手全攻略】
查看>>
【有道云笔记手机PC端自动同步】
查看>>
【黑色蕾丝性感女神XP电脑主题】
查看>>
【XP系统命令提示符都有哪些运用技巧】
查看>>
【4个Win7系统轻松清理记录小技巧】
查看>>
【页面脚本错误快速解决方案】
查看>>
【php输出内容乱码解决方法】
查看>>
【Win8两种安全模式互相切换图形说明】
查看>>
【Win7系统去掉磁盘保护教程】
查看>>
【炫酷战机Win7热门主题】
查看>>
【可爱接吻鱼电脑主题】
查看>>
【详细介绍常见XP系统的配置要求】
查看>>
【解决使用scp命令时不必输入密码的程序】
查看>>
【无敌海景清醒电脑xp主题】
查看>>
【性感玫瑰&热门Win7主题】
查看>>