Angular常用指令

本文详细介绍如何使用Node.js和Angular CLI快速搭建Angular项目,包括安装Node.js、安装Angular CLI、创建新应用、启动项目、生成组件和服务等内容。
安装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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值