Angular CLI 命令可帮助我们非常快速地创建和启动项目。
npm install -g @angular/cli
要创建一个新项目,我们可以在命令行中运行以下命令,然后将创建该项目。
ng new PROJECT-NAME cd PROJECT-NAME ng serve
ng serve //将编译,您可以在浏览器中看到项目的输出-
http://localhost:4200/
创建新项目时,默认端口为4200。您可以使用以下命令更改端口-
ng serve --host 0.0.0.0 --port 4201
Angular 更新命令
如果您想更新应用程序及其依赖关系,可以使用以下命令-
ng update @angular/cli @angular/core
它将核心框架更新到最新版本,即Angular 7和angular-cli。您可以将上述命令与以下选项一起使用-
Angular 命令列表
下表列出了使用Angular 7项目时所需的一些重要命令-
序列号 | 命令和说明 |
---|---|
1 | Component ng g component new-component |
2 | Directive ng g directive new-directive |
3 | Pipe ng g pipe new-pipe |
4 | Service ng g service new-service |
5 | Module ng g module my-module |
6 | Test ng test |
7 | Build ng build --configuration=production //用于生产环境 ng build --configuration=staging //用于说明环境 |
每当创建新模块,组件或服务时,它们的引用都会在父模块 app.module.ts 中更新。