Skip to content
CodingThailand's Blog
CodingThailand's Blog

by โค้ชเอก

  • Home
  • About Me
  • CodingThailand.com
CodingThailand's Blog

by โค้ชเอก

สรุป 13 คำสั่ง การใช้งาน Angular CLI ที่ใช้บ่อยๆ ครับ

12/04/201712/04/2017

Angular CLI เป็นเครื่องมือแบบ command line interface ช่วยให้เราเขียน Angular ได้ง่าย และยังช่วยจัดโครงสร้างและโค้ดให้ถูกต้องตามหลักของ Best Practices อีกด้วย ถ้าใครจะเริ่มเขียน Angular ก็แนะนำให้ใช้ และศึกษาได้เลยครับ 🙂

.
1. ติดตั้ง Angular CLI (แบบ global) ด้วยคำสั่ง
npm install -g @angular/cli

.
2. ดู help ทั้งหมดของ Angular CLI ด้วยคำสั่ง
ng help

.
3. ดูเวอร์ชัน Angular CLI ด้วยคำสั่ง
ng -v

.
4. เปิดดู doc และค้น keyword ในเว็บ angular.io ด้วยคำสั่ง
ng doc [คำที่ต้องการค้น]

.
5. สร้างโปรเจคใหม่ ด้วยคำสั่ง
ng new [ชื่อโปรเจค]
Options ที่น่าสนใจ
5.1 –skip-install หากยังไม่ต้องการติดตั้ง packages ต่างๆ
5.2 –skip-tests หากไม่ต้องการให้สร้างไฟล์ test (spec files)
5.3 –routing หากต้องการให้สร้าง routing module แยกต่างหาก
5.4 –prefix [ข้อความ prefix] ตั้ง default selector prefix ของทุก components
5.5 –skip-git หากไม่ต้องการเพิ่มโปรเจคเข้าไปใน git
ตัวอย่างการใช้
ng new MyProject –routing –style sass prefix hello –skip-git

.
6. หากต้องการ set ค่า config ต่างๆ ในภายหลัง (ในไฟล์ .angular-cli.json) ใช้คำสั่ง
ng set เช่น ng set defaults.styleExt sass
* ใช้ -g ต่อท้าย สำหรับ global set

.
7. ตรวจสอบความถูกต้อง และจัดการโค้ด typescript ที่เราเขียน ด้วยคำสั่ง
ng lint

.
8. สร้าง หรือ gen ไฟล์ blueprint ด้วยคำสั่ง
ng generate หรือ ng g
เช่น หากต้องการสร้าง component ก็ให้ใช้คำสั่ง ng generate component <ชื่อ component> หรือ ng g c <ชื่อ component>
หรือถ้าต้องการสร้าง module และ routing module ด้วย ก็ให้ใช้คำสั่ง ng g m <ชื่อ module> –routing
หรือต้องการสร้าง Routing Guard ก็ใช้คำสั่ง ng generate guard <ชื่อ guard>

.
9. Serve โปรเจค ด้วยคำสั่ง
ng serve
Options ที่น่าสนใจของ ng serve
9.1 –open หรือ -o ไว้เปิด default browser เช่น ng serve -o
9.2 –port หรือ -p ระบุ port ที่ต้องการ เช่น ng serve -p 8626

.
10. Build โปรเจค (Development Build) ด้วยคำสั่ง
ng build

.
11. Build โปรเจค (Production Build) ด้วยคำสั่ง
ng build –prod

.
12. Unit Tests (Karma) ด้วยคำสั่ง
ng test

.
13. End to End Tests (Protractor) ด้วยคำสั่ง
ng e2e

Views: 11103

Angular

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts ล่าสุด

  • การใช้งาน Prefetching ใน Next.js
  • 14 ข้อคิด เพื่อการเป็น Developer ที่ดีขึ้น จาก “Lee Robinson”
  • เคยเจอ “TypeError: Cannot read property ‘x’ of undefined” หรือเปล่า
  • บันทึกการเขียนเว็บไซต์ใหม่ในรอบ 10 ปี ย้ายมาใช้ Next.js
  • ทำไมการจัดการ Error ใน JavaScript ถึงเป็นเรื่องท้าทาย?

Recent Comments

    หมวดหมู่

    • .NET
    • AI
    • Android
    • Angular
    • Angular 2
    • Coding
    • CSS
    • Database
    • Editor
    • Flutter
    • Git
    • HTML5
    • Ionic 2
    • Ionic 4
    • Ionic Framwork
    • JavaScript
    • Laravel
    • Laravel 5
    • Next.js
    • Node.js
    • PHP
    • PHP 7
    • Plugins
    • React
    • React Native
    • Template
    • Tools
    • TypeScript
    • UI
    • Uncategorized
    • Vue.js
    • XAMPP
    • Yii
    • คอร์สเรียน
    • แรงบันดาลใจ

    Archives

    • July 2025
    • April 2025
    • November 2024
    • October 2024
    • April 2020
    • February 2020
    • August 2019
    • September 2018
    • August 2018
    • February 2018
    • November 2017
    • October 2017
    • August 2017
    • July 2017
    • April 2017
    • October 2016
    • August 2016
    • May 2016

    Tags

    .NET android Angular Angular 2 Atom Coding Coding Standard CSS CSS 3 Datepicker Express.js extensions Git HTML HTML5 Ionic2 JavaScript Laravel5 laravel 5.5 MariaDB Material Design MySQL Node.js npm PHP PHP7 plugins PouchDB recaptcha Restful sail.js template typescript typscript XAMPP Yii2

    ผู้เยี่ยมชม

    • 0
    • 1,818,181
    • 547,566
    • 11,103
    ©2025 CodingThailand's Blog | WordPress Theme by SuperbThemes