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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM