Angular常用指令

安装Node

先去Node官网下载并安装Node.js

Install the Angular CLI(安装Angular CLI)

npm install -g @angular/cli

Create a new application(创建新项目)

ng new your-application-name

Serve the application(启动项目)

ng serve

Create the component(创建component)

ng generate component your-component-name

如果不想要.html文件,采用模板内嵌的方式,使用下列指令

ng generate component your-component-name -it

Create the service(创建Service)

ng generate service your-service-name

有几种方式注入服务,在对应的Component中,在AppComponent中,在AppModule中。每个选项都有优点和缺点。
在AppModule中注入服务,通过追加--module = app来完成。

ng generate service your-service-name --module=app

在生成的时候没有指定方法,也可以手动注入服务。

Creating a class(创建Class)

ng generate class your-class-name

Add the AppRoutingModule(添加路由)

ng generate module app-routing --flat --module=app

--flat将文件放在src / app中而不是它自己的文件夹中。
--module = app告诉CLI将其注册到AppModule的imports数组中。

Install package from npm(安装npm包)

Install the In-memory Web API package from npm

npm install angular-in-memory-web-api --save

发布

ng build --prod

--prod表示压缩

参考资料 Angular CLI

https://github.com/angular/angular-cli/wiki/stories
https://cli.angular.io/
https://angular.cn/guide/cheatsheet
https://segmentfault.com/a/1190000009771946

原文地址:https://www.cnblogs.com/Lulus/p/8488608.html