hello world Angular โดยใช้ cli

#angular24 ก.ย. 2567

hello world Angular โดยใช้ cli

มาดูวิธีการ hello world ใน angular โดยใช้ cli กันครับ

ก่อนอื่นก็เตรียมของตามนี้

Prerequisites

  • Node.js - v^18.19.1 or newer
  • Text editor - We recommend Visual Studio Code
  • Terminal - Required for running Angular CLI commands

จากนั้นเราก็มาติดตั้ง cli โดยใช้คำสั่ง

npm install -g @angular/cli

เมื่อติดตั้งเสร็จ เราก็ไปสร้างโปรเจ็คกันครับ


สร้างโปรเจ็ค

ใช้คำสั่ง

ng new <project-name>

เมื่อสร้างเสร็จ แล้วเราก็ไปลอง start โปรเจ็คที่เราสร้างกันดูครับ โดยใช้คำสั่ง

npm start

เมื่อ start เสร็จ เราจะเห็น Log ตามตัวอย่างด้านล่าง

Watch mode enabled. Watching for file changes...
NOTE: Raw file sizes do not reflect development server per-request transformations.
 ➜ Local: http://localhost:4200/
 ➜ press h + enter to show help

เมื่อ start เสร็จแล้ว เราลองไปรันกันได้ที่ port 4200 ในเครื่องครับ ตามลิ้ง http://localhost:4200

แหล่งอ้างอิง https://angular.dev/installation