Tuesday 13 November 2012

AngularJS - JavaScript MVC Framework powered by Google




AngularJS คือ JavaScript Framework อีกตัวหนึ่งที่ช่วยในการพัฒนา Web Application ในรูปแบบ MVC (Model-View-Controller) มีจุดเด่นคือ ความง่ายในการใช้งาน เขียน Code ไม่เยอะ รองรับการทำ Data Binding แบบ Bi-Direction (เวลาที่เราแก้ไข View จะส่งผลให้ Model มีการ update โดยอัตโนมัติ ในทำนองเดียวกัน เวลาที่เราแก้ไข Model ก็จะส่งผลให้ View มีการ update โดยอัตโนมัติเช่นเดียวกัน) การใช้งาน AngularJS สามารถใช้งานได้ง่าย เพราะไม่ต้องมีการ extend class อย่างเช่น Model , View , Controller ก่อนการใช้งาน (ซึ่งถือเป็นจุดเด่นที่แตกต่างจาก MVC Framework อย่าง Backbone) การนำ MVC Framework มาใช้ในการ Develop Web Application จะช่วยให้เราสามารถแยกส่วนที่เป็น Presentation (HTML) ออกจากส่วนที่เป็น Coding (JavaScript) ทำให้แก้ไขได้ง่าย การควบคุมการทำงานของ Web Application ใน Angular.js จะทำผ่าน Controller ซึ่งถือเป็นแกนหลักในการทำงาน โดยหลักในการทำงาน จะอาศัยการ binding ส่วนที่เป็น UI บนหน้าเว็บของเราเข้ากับตัว Controller จากนั้นเราจะเขียน Code สำหรับควบคุมการทำงานทั้งหมดผ่าน Controller นี้ ไม่ว่าจะเป็นการ ลบ เพิ่ม แก้ไข ข้อมูล หรือ อะไรก็แล้วแต่ ซึ่ง Code ภายในส่วนของ Controller นั้นจะมองเห็นข้อมูลของหน้าเว็บเราผ่านทาง Model (เราต้องทำการ binding UI element ให้เป็น Model ก่อน ผ่าน attribute ที่ชื่อว่า ng-model)

Web Application ที่เราพัฒนาขึ้นโดยใช้ AngularJS สามารถแบ่งการทำงานออกเป็นหลาย Controller ได้ โดยเราสามารถกำหนด config ของ Application เพื่อให้ route ไป ยัง controller แต่ละตัวได้ นอกจากนั้น เรายังสามารถพัฒนาความสามารถเพิ่มเติม โดยสร้างเป็น module ผ่านทาง factory method ที่ AngularJS เตรียมไว้ให้ ทำให้ code ของเรามีความเป็นระเบียบเรียบร้อย สำหรับ class ช่วยเหลือต่างๆที่จำเป็นก็มีเตรียมไว้ให้ใช้งาน อย่างเช่น HTTP Object เพื่อเอาไว้สร้าง AJAX Request เป็นต้น

โดยรวมๆ ถือว่าใช้งานง่ายครับ พอลองใช้งานแล้วก็รู้สึกชอบทันที เป็น Framework ที่หลวมๆ ไม่ค่อยมีกฎเกณฑ์อะไรมาก ช่วยให้เราเขียน Web Application ได้ง่ายขึ้น ไม่ต้อง extend class ต่างๆให้วุ่นวาย เขียน code น้อย เพราะการใช้ data binding จะช่วยลดการเขียน code ลงได้เยอะ เพราะเราไม่ต้อง query DOM element เพื่อทำการ update เอง แต่ตัว Framework จะจัดการให้เสร็จเรียบร้อย อันนี้เป็นความเห็นส่วนตัวของผมเอง ยังไงก็ไปลองเล่นดูกันเอาเองแล้วกันนะครับ อาจจะชอบหรือไม่ชอบไมรู้ แต่ผมชอบ!

แหล่งที่มา : http://angularjs.org

12 comments:

  1. ผมเองก็ชอบครับยิ่งตอนที่เราอัพเดทข้อมูลในโมเดลแล้ว View มีการอัพเดทตามนี้เป็นอะไรที่ชอบมาก ใช้งานง่ายเรียนรู้ไม่ยากแค่มีพื้นฐาน HTML+JavaScript ก็สามารถใช้งานได้แล้ว

    ปล. บทความเกี่ยวกับ AngularJs ที่เป็นภาษาไทยไม่ค่อยมีเลยครับ ขอบคุณครับ

    ---
    รับทำเว็บในจังหวัดระยอง http://4dbag.com

    ReplyDelete
  2. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools
    Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton
    of engaging advice and insight into front-end technologies. Even more obvious is his passion
    for open source contribution and trial-and-error development, making his blog one of the
    most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  3. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  4. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  5. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  6. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  7. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  8. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  9. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  10. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  11. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete
  12. David Walsh is Mozilla’s senior web developer, and the core developer for the MooTools Javascript Framework. David’s blog reflects his skills in HTML/5, JS and CSS, and offers a ton of engaging advice and insight into front-end technologies. Even more obvious is his passion for open source contribution and trial-and-error development, making his blog one of the most honest and engaging around.
    Website: davidwalsh.name

    ReplyDelete