Angular 7:命令行
Angular CLI 使得开始任何Angular项目都很容易。Angular CLI 附带命令帮助我们快速创建和启动项目。现在让我们来看看创建项目、组件和服务、更改端口等可用的命令。
要使用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
它将把核心框架更新到最新版本,即 Angular7和 Angular cli。您可以将上述命令与以下选项一起使用
Angular 重要的命令列表
下面列出了使用Angular7项目时需要的几个重要命令
Component
ng g component new-component
Directive
ng g directive new-directive
Pipe
ng g pipe new-pipe
Service
ng g service new-service
Module
ng g module my-module
Test
ng test
Build
ng build --configuration=production // for production environment ng build --configuration=staging // for stating environment
每当创建新模块、组件或服务时,其引用都会在父模块app.module.ts中更新。