Angular CLI คือเครื่องมือบรรทัดคำสั่งสำหรับสร้าง จัดการ รัน ทดสอบ และ build โปรเจกต์ Angular ช่วยลดงานซ้ำและทำให้โครงสร้างโปรเจกต์เป็นมาตรฐานเดียวกัน
%%{init: {"theme": "base", "themeVariables": {"primaryColor": "#fabd2f", "primaryTextColor": "#282828", "primaryBorderColor": "#b57614", "lineColor": "#7c6f64", "secondaryColor": "#83a598", "tertiaryColor": "#b8bb26", "background": "#fbf1c7", "mainBkg": "#ebdbb2", "fontFamily": "Tahoma, sans-serif"}}}%%
flowchart LR
subgraph Era1["ยุคเริ่มต้น / Early Angular"]
A["AngularJS 1.x
Framework รุ่นแรก"]
end
subgraph Era2["ยุค Angular 2+ / Modern Angular"]
B["Angular CLI
สร้าง Project มาตรฐาน"]
C["TypeScript
ภาษาแกนหลัก"]
end
subgraph Era3["ยุคปัจจุบัน / Current Tooling"]
D["Standalone + Build Tools
พัฒนาเร็วขึ้น"]
E["Production Build
Deploy พร้อมใช้งาน"]
end
A --> B --> C --> D --> E
npm install -g @angular/cling versionng new project-nameng generate component/service/pipe/directive/moduleng serve --port 4200ng build --configuration productionng testangular.jsonng newng servehttp://localhost:4200| คำสั่ง | หน้าที่ | ใช้เมื่อใด |
|---|---|---|
ng new |
สร้างโปรเจกต์ | เริ่มงานใหม่ |
ng generate component |
สร้าง Component | ต้องการ UI ใหม่ |
ng generate service |
สร้าง Service | แยก Logic หรือ API |
ng serve |
รัน Dev Server | พัฒนาระหว่างเขียนโค้ด |
ng build |
สร้างไฟล์ Deploy | เตรียมขึ้น Production |
ng test |
รันทดสอบ | ตรวจคุณภาพโค้ด |
%%{init: {"theme": "base", "themeVariables": {"primaryColor": "#fabd2f", "primaryTextColor": "#282828", "primaryBorderColor": "#b57614", "lineColor": "#7c6f64", "secondaryColor": "#83a598", "tertiaryColor": "#b8bb26", "background": "#fbf1c7", "mainBkg": "#ebdbb2", "fontFamily": "Tahoma, sans-serif"}}}%%
flowchart TD
A["ติดตั้ง CLI
Install CLI"] --> B["สร้างโปรเจกต์
ng new"]
B --> C["สร้างส่วนประกอบ
ng generate"]
C --> D["รันทดสอบระหว่างพัฒนา
ng serve"]
D --> E["ทดสอบโค้ด
ng test"]
E --> F["Build สำหรับใช้งานจริง
ng build"]
# ติดตั้ง Angular CLI แบบ global
npm install -g @angular/cli
# ตรวจสอบเวอร์ชัน Angular CLI
ng version
# สร้างโปรเจกต์ใหม่ พร้อม routing และใช้ CSS
ng new web-learning --routing --style css
# เข้าโฟลเดอร์โปรเจกต์
cd web-learning
# สร้าง component สำหรับแสดงบทเรียน
ng generate component lesson-card
# สร้าง service สำหรับจัดการข้อมูลรายวิชา
ng generate service course
# รัน dev server ที่ port 4200
ng serve --port 4200
# ตัวอย่างการใช้งาน:
# เปิด Browser ที่ http://localhost:4200
web-coursecourse-listcourse-data