<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Puck on Medium]]></title>
        <description><![CDATA[Stories by Puck on Medium]]></description>
        <link>https://medium.com/@neverzero9?source=rss-46d76a699bbc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*K738CHAI1tIhYVGF</url>
            <title>Stories by Puck on Medium</title>
            <link>https://medium.com/@neverzero9?source=rss-46d76a699bbc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 13 Nov 2026 22:16:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@neverzero9/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[ย้อนรอยประวัติศาสตร์ไปพบกับเจ้า AngularJS รุ่นเก่า ที่ยังเก๋ากัน!!]]></title>
            <link>https://medium.com/@neverzero9/%E0%B8%A2%E0%B9%89%E0%B8%AD%E0%B8%99%E0%B8%A3%E0%B8%AD%E0%B8%A2%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%A7%E0%B8%B1%E0%B8%95%E0%B8%B4%E0%B8%A8%E0%B8%B2%E0%B8%AA%E0%B8%95%E0%B8%A3%E0%B9%8C%E0%B9%84%E0%B8%9B%E0%B8%9E%E0%B8%9A%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B9%80%E0%B8%88%E0%B9%89%E0%B8%B2-angularjs-%E0%B8%A3%E0%B8%B8%E0%B9%88%E0%B8%99%E0%B9%80%E0%B8%81%E0%B9%88%E0%B8%B2-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%A2%E0%B8%B1%E0%B8%87%E0%B9%80%E0%B8%81%E0%B9%8B%E0%B8%B2%E0%B8%81%E0%B8%B1%E0%B8%99-30111d7c8eb3?source=rss-46d76a699bbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/30111d7c8eb3</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[angular-js-app]]></category>
            <category><![CDATA[angularjs-programming]]></category>
            <dc:creator><![CDATA[Puck]]></dc:creator>
            <pubDate>Wed, 27 Jun 2018 10:24:00 GMT</pubDate>
            <atom:updated>2018-06-27T11:18:58.743Z</atom:updated>
            <content:encoded><![CDATA[<p>ย้อนรอยประวัติศาสตร์ไปพบกับเจ้า AngularJS รุ่นเก่า ที่ยังเก๋ากัน!!</p><p>ถึงแม้เจ้า AngularJS จะได้ชื่อว่าเป็น Version แรกสุดและเก่าสุดของ Angular Framework แต่ก็ต้องยอมรับว่ายังมี Team Developer อีกพอสมควร ที่ยังคงใช้ AngularJS กันอยู่ ถึงจะได้ชื่อว่าเป็น version บุกเบิก แต่มันก็ยังคงถูก support โดยทีมผู้พัฒนาอยู่เสมอ แม้จะฟังดูเก่า แต่ในการรับงาน ปรับปรุง/แก้ไข/ต่อเติมเว็บไซต์ ก็เป็นอีกเรื่องที่หลีกเลี่ยงไม่ได้เช่นกัน ที่จะต้องเจอกับเจ้า AngularJS Framework เพราะจะทำใหม่หมดก็คงไม่คุ้ม ไหน ๆ ก็ เลี่ยงไม่ได้แล้ว ถ้างั้นยอมจำนนแล้วมารู้จักกับเจ้า Angular ใน Version JS กันซะดีๆ!!</p><p>และในบทความนี้จะพูดถึงการใช้ AngularJS เป็นหลักในรูปของ Static Web โดยใช้ HTML CSS + Bootstrap เป็น View และ Javascript เป็น Controller ดังนั้น . . .</p><ul><li>สิ่งที่ควรคุ้นเคยก่อนอ่านบทความนี้<br>- HTML CSS Bootstrap<br>- Javascript <br>- Front-end Framework (คุ้ยเคยหรือเคยเล่น framework ซักตัวมาบ้าง)<br>นะจ๊ะ . . เพราะอาจจะไม่ได้สาธยายเกี่ยวกับเจ้าพวกนี้มากนัก แต่ก็จะแป่ะเป็น Link เนื้อหาให้แทนละกัน</li><li>วัตถุประสงค์ของเรา<br>1. สร้าง View Table รายการสินค้า<br>2. สร้าง Congroller เพื่อจัดการกับ model และทำ Search<br>3. สร้าง Service เพื่อให้ Controller เรียกใช้งาน <br>เราจะไม่ได้เข้าไปถึงขั้น Advance แต่อย่างใดในบทความนี้ เราจะเอาแค่ Simple ๆ นั้นก็คือเข้าใจเจ้า AngularJS นั้นเอง</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*Dxvd5mc9Y5QyDNMmcwNUiw.jpeg" /></figure><p>เริ่มกันเลยดีกว่า . . . ช้าอยู่ใย Setup Project ให้ได้โครงสร้างตามนี้ซะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*VCUOOhal6WUVblSe7F2UjA.png" /></figure><p>จะ Spoil ให้ว่าทั้งบทความเราก็จะมีไฟล์ Suck ๆ อยู่กันแค่สามตัวนี้แหละจ้าา<br>ใครจะใช้ IDE อื่น ไม่ว่ากันนะ . . แต่ฉันจะใช้ VS CODE สุดแค้นแสนรัก++</p><p>มา!! เริ่มวัตถุประสงค์กันเลยดีกว่า<br>“1. สร้าง View Table รายการสินค้า”<br>จัดการยัดมันเข้าไปเลย++</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LX-CAhn4pQulAfHfY2liRQ.png" /></figure><p>ในส่วนของหน้าหลัก html ของเรา ก็ไม่มีอะไร Extra นอกจากการ Setup แบบบ้าน ๆ ด้วย reference ไปยัง Css Library Bootstrap ตามด้วยพระเอกอย่าง AngularJS Sctipt และ Include เจ้าไฟล์ app.js และ style.css ของเราเข้าไปด้วย</p><p>อ๊ะ . . วาป! สำหรับ version ปัจจุบันที่ใช้ในบทความนี้</p><blockquote>Bootstrap: <br><a href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css</a></blockquote><blockquote>AngularJS: <br><a href="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js">https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js</a></blockquote><p>แต่การ Setup เจ้า AngularJS ของเรายังไม่เสร็จสิ้นนะเออ! <br>Step สุดท้ายในการ Setup เจ้า Project ของเรา</p><p>อ่ะ จัดการยัดเจ้า Expression 1+1={{ 1+1}} และ Directive “ng-app” ลงไปในหน้า html ของเราซะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o9xF_IM1zMT3iqCaXyoLrg.png" /></figure><p>เฮ้ ๆ ไหนลองเปิด index.html ดูซิ++</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-MExZZdtTEy6OawP8NDglA.png" /></figure><p>Yassss! นั้นก็ถูกต้องแล้วแล</p><p>แต่ เอ…. เจ้าปีกกา expenssion พอคุ้นเคยนะ แต่เจ้า ng-app นี้สิคืออะไร ?</p><p>แท้จริงแล้วมันก็คือหนึ่งใน Directive ของ AngularJS นั้นแล ซึ่งเป็นจุด Start Point ของ AngularJS เพราะถ้าหากขาดมันไปแล้วล่ะก็ เราก็จะไม่สามารถที่จะ Run เจ้าโปรเจ็ค AngularJS ของเราขึ้นมาได้<br>… จริงหรอ ? … ไหนลองซิ!! ขยี้มันออกเลยแล้วรันใหม่!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*OEPlcxcj66JvH2DzFrcjIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*DNlVBmbL_COW2jtJOZRZaA.png" /></figure><p>เย้++ Expression ไม่ออกแล้ว . . . จะบ้าเร๊อะ!!</p><p>ก็เพราะเจ้า ng-app นั้นคือจุด Start Point ของเจ้า AngularJS Application ไงจ๊ะนายจ๋า . . เจ้า AngularJS จะเริ่มต้นเช็คหา ng-app Directive ที่ไหนซักแห่งในหน้าเพจ html ของเรา ซึ่งเมื่อเจ้า AngularJS ตรวจพบเจ้า ng-app เมื่อไหร่ มันก็จะ Bootstrap ตัวมันเองขึ้นมาและเข้าไปจัดการในส่วนของหน้า UI ใน tag นั้น ๆ</p><p>เอ . . . . แปลว่า ถ้าเราไประบุเจ้า ng-app วันไว้ที่อื่น แล้วเรียกใช้ expressions ไว้นอก tag html มันจะ error ? . . . ไหนลองซิ!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PyJev0pvjYo6b5ITtvS3g.png" /></figure><p>ลองใส่ expression {{ 2 + 2 }} ไว้ใน tag ที่มี ng-app<br>และ {{ 1 + 1 }} ไว้นอก tag ที่มี ng-app</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*2f6Au2Diu63E5mivY3l_fw.png" /></figure><p>เย้ ออกอันเดียว . . . <br>อ่าว ก็แน่นอนล่ะซิ ก็เพราะเราไปใส่เจ้า ng-app ไว้ในแท็ก &lt;div&gt; แต่เจ้า {{ 1 + 1 }} ของเราดันไปอยู่นอก Scope ของเจ้า &lt;div&gt; ที่มี ng-app เข้า มันจึงเป็นเหตุผลว่าทำไมเราถึงใส่มันไว้ตรง tag &lt;html&gt; ตั้งแต่แรก <br>. . . แต่จริง ๆ ตรง tag &lt;body&gt; ก็ได้นะเออ<br>. . . แต่จริง ๆ ใส่ไว้หลาย ๆ ที่ก็ได้นะเออ <br>. . . ก็เอาที่สะบายใจละกันนะเออ . . . เพราะบางครั้งเราอาจจะต้องการ Module หลาย ๆ ตัวเพื่อที่จะเขียนเว็บใน Scale ใหญ่ ๆ ดังนั้นจะทำ module ออกมากี่ตัวก็ขึ้นอยู่กับความต้องการโดยรวมนะเออ</p><p>เอ้า!! มาต่อ++ <br>จัดการสร้าง View Table Product List ด้วย html css bootstrap</p><p>ในบทความนี้จะไม่สาธยายเกี่ยวกับเจ้า css เลยแต่อย่างใดน่ะจ๊ะ เพราะเกรงว่ามันจะยาวเกินไป ถ้าเช่นนั้นแล้ว เอาเจ้า code css กาก ๆ ตัวนี้ไปใส่ไว้ใน style.css ของเรากันได้เลย</p><blockquote>.center {<br>text-align: center;<br>margin: auto;<br>}<br>.turn-text-left {<br>text-align: left;<br>}<br>.turn-text-right {<br>text-align: right;<br>}<br>.space5 {<br>padding: 5%;<br>}<br>.margin-2px {<br>margin: 2px;<br>}<br>.padding-space {<br>padding: 5px;<br>}</blockquote><p>และ . .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*Z_Lq7R71uXrIDeyJpyjFZQ.png" /></figure><p>ถ้าใครลอกทุกบรรทัดก็แก้เจ้าตัวนี้ด้วยนะเออ เพาะตามจริงแล้วมันต้องเป็น style.css ตามโครงสร้างโปรเจ็คของเรา เดี๋ยวเจ้า html ของเราจะหา css ไฟล์ไม่เจอ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QU6EesezOuk6AejpPUFtjQ.png" /></figure><p>เสร็จเราก็มาต่อกันที่ tag &lt;body&gt; จัดการใส่เจ้าพวก html css เข้าไป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Agcf2rJ8rpCVW3dd_DIVqA.png" /></figure><p>แล้วเราก็จะได้ index.html รูปร่างหน้าตาเช่นนี้ . . . ว่าแล้วก็รันมันขึ้นมาเลย++</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ufefj9rjkSK-CMjwmZbWpw.png" /></figure><p>เอ . . . ยังขาด Table นะ งั้นใส่มันเข้าไปอีกดีกว่า แทรกระหว่าง UI Search และ script reference ของเรา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QAAqQbD9dhsKSs9v60Uytw.png" /></figure><p>แล้วเราก็จะได้ Overview เช่นนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pl22yu-67DLVBONbR4Z9oA.png" /></figure><p>เสร็จแล้ว Run ดูหน้าเว็บกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2FZEXDmM2FI1g8wGxJsKnw.png" /></figure><p>Yesss !! และในที่สุดเราก็จบในส่วนของ UI ซักที <br>มา! ต่อกันในส่วนของ Controller กันดีกว่า เปิดไฟล์เจ้า app.js ขึ้นมากันเลย!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*Y9dzgdXlJRUR_GBvKlmR-Q.png" /></figure><p>และในวัตถุประสงค์ที่สองของเราก็คือ <br>“2. สร้าง congroller เพื่อจัดการกับ model และทำ search”</p><p>เราจะมาเริ่มต้นด้วยการสร้าง Module และ Controller ให้กับเจ้า ng-app ของเรากัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*-fyy0jS8MuJrYqdr0EqxPg.png" /></figure><p>โดยเราจะเริ่มต้นแบบ Basic ๆ ด้วยการแทนค่า</p><blockquote>var app = angular.module( ‘myApp’ , [ ] );</blockquote><p>ซึ่งนี้คือวิธีการสร้าง module ของเรา<br>และ app.controller . . . นั้นก็คือการสร้าง Controller ภายใน Module App ของเรานั้นเอง <br>ดังนั้นเมื่อเราสร้าง Controller ไว้ใน Module ไหน เราก็ต้องเรียกใช้ให้ถูกต้องด้วยนะเออ</p><p>มา! ถึงเวลาเรียกใช้มันแล้ว ใส่มันลงไปใน html ของเรากันเลยดีกว่า</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ERIoh6Cb5vJsQ50puZvxDg.png" /></figure><p>ในส่วนของเจ้า ng-app เราก็ใส่ ชื่อ module “myApp” ที่เราสร้างเข้าไป<br>ส่วนเจ้า ng-controller เราก็ใส่ ชื่อ controller “myController” ของเราที่สร้างใน module “myApp” ซะ</p><p>หลังจากนั้น เราก็จะสามารถเรียกใช้งานเจ้า Variable ต่าง ๆ ที่เราประกาศไว้ภายใน Controller “myController” ของเราได้เลย ดังนั้นก็เรียกมันออกมาแสดงผ่าน expressions ในส่วนของ &lt;tbody&gt; ตามรูปซะ</p><p>ซึ่งในส่วนของ ของ {{ name }} . . บลา ๆ ที่เรา reference ถึงนั้นเราก็หมายถึงเจ้าพวก variable ใน myController ของเรานั้นเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*-FTsasqSDUSK5kgct2AeGg.png" /></figure><p>ซึ่งเจ้า $scope ณ ที่นี้ก็หมายการ Binding Variable ระหว่าง html และ javascript โดยเราจะสามารถเรียกใช้งานมันได้จากหน้า html ผ่าน JS controller</p><p>เอาล่ะ . . ในเมื่อใส่มันเข้าไปเสร็จแล้ว ไหนลองรันดูซิ!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLVWKSrOG0aSgdA4MuPcMg.png" /><figcaption>วงซะเป็นเกมจับผิดภาพเชียว</figcaption></figure><p>เหมือนเดิมเลย แต่ในที่สุดเราก็ได้ model ของเราที่ใส่ไว้ใน controller 3 ตัวนั้นออกมา . . . ok งั้นเรามาต่อกันเลยดีกว่า สร้าง model list ขึ้นมาแล้วเอามันมาแสดงลงใน Table Product เลย</p><p>จัดการขยี้เจ้า model name/price/quantity ออกซะ แล้วใส่ model list ตัวใหม่ของเราเข้าไปแทน</p><blockquote>[{name: ‘Pencil’,price: 7.50,quantity: 140},<br>{name: ‘Cola’,price: 15.75,quantity: 50},<br>{name: ‘Book’,price: 69.50,quantity: 1200},<br>{name: ‘Montor’,price: 2500,quantity: 17},<br>{name: ‘Land Cable’,price: 150,quantity: 94},<br>{name: ‘Mouse’,price: 450.75,quantity: 45},<br>{name: ‘Iphone Cable’,price: 290,quantity: 60},<br>{name: ‘Table’,price: 590,quantity: 4},<br>{name: ‘Pen’,price: 12.75,quantity: 2440},<br>{name: ‘Keybord’,price: 790,quantity: 12},<br>{name: ‘Paper’,price: 0.50,quantity: 1200}]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*1Ex8H2UWuiRRk0ahfog3wg.png" /></figure><p>ในเมื่อเสร็จสิ้นในส่วนของ controller แล้ว เราก็มาจัดการต่อในส่วนของ html กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBCYLH_6mfwR1uf3B_LR-g.png" /></figure><p>ณ จุด ๆ นี้เราจะทำการใส่เจ้า ng-repeat หรือ ng-for ใน Angular2 ขึ้นไป โดยเราจะ loop เอา Object ใน list ของ products ออกมาแสดง โดย Syntax จะต่างกันเล็กน้อยเพราะเราจะใช้ in แทน of ใน Angular Version อื่น ๆ</p><p>และเราจะนำเอาเจ้า attibute ของ product in products มาใส่ใน tag &lt;td&gt; ตามภาพเลยนะจ๊ะ . . . เมื่อใส่เสร็จแล้วก็ Run เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*943SB1fT2U9gK7UaezepVw.png" /></figure><p>และนี้ก็คือผลกรรม เอ๊ยยย . . . ผลลัพธิ์!! Yassssss!! . . . ok ดีใจพอละงั้นทำ Search ต่อเลยดีกว่า</p><p>สำหรับ Search ในที่นี้ไม่ได้ยากเลยแม้แต่นิด น่ะจ๊ะ . . เพราะเราจะใช้ฟีเจอร์ของเจ้า AngularJS กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WSp96AYK548iAozYolNCw.png" /></figure><p>โดยเราก็จะใส่เจ้า ng-model ที่เป็น Two-Way Binding เข้าไป <br>และในส่วนของ ng-repeat นั้นเราก็จะใส่ filter เข้าไปโดยมี “|” หรือที่บางคนเรียกกันว่า pipe คั่นกลาง</p><blockquote>Data Binding<br>https://docs.angularjs.org/guide/databinding<br><a href="https://www.w3schools.com/angular/angular_databinding.asp">https://www.w3schools.com/angular/angular_databinding.asp</a></blockquote><blockquote>Filter &amp; Pipe<br><a href="https://docs.angularjs.org/api/ng/filter/filter">https://docs.angularjs.org/api/ng/filter/filter</a></blockquote><p>. . . . Run ดูซิจ๊ะ!! แล้วลอง Search กันดูในช่อง Input ด้วย “Pen” keyword</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6JdZuGWwixMPzGe8jJr7g.png" /></figure><p>ไหนดูผลลัพธิ์ซิ๊++ Yessss! นี้แหละที่สังคมต้องการ <br>แต่ไหน ๆ ก็ได้ใช้ filter ในการ Search ไปแล้ว <br>เรามาใช้ filter ในการ Reformat เจ้า price และ quantity ด้วยเลยดีกว่า</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ymhRqv7HnZCo9UgNQAiKw.png" /></figure><p>จัดการใส่ pipe คั่นและใส่ Filtter เข้าไป<br>กับ quantity เราจะใช้ Filter ||number: “จำนวนจุดทศนิยม”<br>ส่วน price เราจะใช้ Filter ||currency: “สัญญาลักษณ์ค่าเงิน“:”จำนวนจุดทศนิยม”<br>เสร็จแล้วเรามาดูผลลัพธิ์กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*11IJ3p53qHQk9DmSs4Tv0Q.png" /><figcaption>อย่างกะ Review ทำนมยังไงยังงั้น…</figcaption></figure><p>ถึงแม้ในส่วนของ quantity เราจะใส่เป็นจุดทศนิยม 0 ตำแหน่งไปและเหมือนไม่ได้อะไร แต่ถ้าสังเกตุให้ดี ๆ ล่ะก็ เราก็ได้ , มาอยู่นะจ๊ะ</p><blockquote>สงสัย ณ จุดไหนเพิ่มเติมเข้าไปอ่าน API Reference ได้เลย<br><a href="https://docs.angularjs.org/api/ng/filter/filter">https://docs.angularjs.org/api/ng/filter/filter</a></blockquote><p>ในที่สุดก็มาถึงวัตถุประสงค์สุดท้ายกันซักทีกับข้อที่สาม<br>“3. สร้าง Service เพื่อให้ Controller เรียกใช้งาน”<br>ถึงเวลา ย้าย model กันแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*mZLodDebFFDKJ6UfQVzBBg.png" /></figure><p>งงอ่ะดิ งั้นเอาไปอีกรูป ดูคู่กันพร้อมอ่าน นะจ๊ะ ถึงจะเข้าใจง่ายขึ้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hmaaR4DR73ubE3QAHnUw2A.png" /></figure><p>โดยเราจะสร้างเจ้าตัว Service ขึ้นมา ตามภาพและย้ายเจ้าโมเดล Products ไปไว้ใน Service แทนโดยใช้ชื่อว่า data และเปลี่ยนจาก $scope.products เป็น this.product และขยี้เจ้า $scope ทิ้งซะ เพราะตอนนี้มันหมดประโยชน์แล้ว Yeah!!!</p><p>หลังจากนั้นเราก็ทำการเปลี่ยน Parameter ช่องที่สอง ของ app.controller ให้กลายเป็น Array [ ] เพื่อที่จะสามารถ Inject เจ้า “MyService” ของเราเข้าไปให้ Controller เรียกใช้ได้ และอย่าลืมยัดเอาเจ้า function เข้าไปในนั้นด้วย</p><p>แต่เดี๋ยวก่อน . . .มันยังไม่จบน่ะจ๊ะ เพราะเราต้องจะต้อง reference พวก Model ต่าง ๆ ของเราที่ก่อนหน้านี้เราใช้ $scope แต่ตอนนี้เราเปลี่ยนเป็น this ไปแล้วดังนั้นเราต้องใช้วิธีการเรียกแบบใหม่ โดยจะเรียกผ่าน “myController” Object แทน เพื่อให้สามารถหา model เจอได้จากไฟล์ html . . . งง มะ ? . . . งั้นไปดูกัน . . .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5UoAU7eHpfV-WpVloq0dA.png" /></figure><p>Okey ในไฟล์ html จากเดิมที่เราสามารถเรียกใช้ variable ได้เลยโดยตรง แต่ตอนนี้เราต้องเรียกใช้งานมันผ่าน controller ของเราในรูปแบบของ Object แทน ซึ่งก็คือเจ้า “myController”</p><p>เอ. . . . แต่ถ้าจะให้เรียกใช้ผ่านชื่อเต็มอย่าง myController.products บลา ๆ มันก็จะดูยาวไปหน่อย . . . ดังนั้นเรามาตั้งชื่อย่อสั้น ๆ หรือ Short nameให้มันแล้วเรียกใช้แทนชื่อเต็มจะดีกว่า</p><p>โดยเราจะสามารถตั้งชื่อใหม่ให้กับเจ้า myController ของเราได้ด้วย keyword ง่าย ๆ นั้นก็คือ ass . . . เอ้ยย~ ไม่สิ s ตัวเดียว</p><blockquote>Rename | ng-controller=”myController as ctl”<br>Call by full name |myController.products<br>Call by short name |ctl.products</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*943SB1fT2U9gK7UaezepVw.png" /></figure><p>Yaddddddddssssss!! output เหมือนเดิมเลย แต่ในที่สุดก็ครบ 3 วัตถุประสงค์ซักที แต่ เอ . . . นะ ทำไมเราต้องแยกเอา model ของเราจาก Controller ไปไว้ใน Service ทำไมให้มันยุ่งยากล่ะ ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zx64JQqMCi7rwEPEKczsKA.png" /></figure><p>ถูกต้องแล้วจ่ะ จริง ๆ เราเก็บเจ้า model ของเราเอาไว้ใน controller ทั้งหมดเลยก็ได้ ไม่จำเป็นเลยซักนิดที่เราต้องแยกมันไปใส่ใน Service แล้ว Inject เข้ามาแทน</p><p>. . . เอ … แต่ถ้าเช่นนั้นแล้วเราจะมี Service ไว้ทำมะเขือพวงอะไรกัน O.o?</p><p>ซึ่งแน่นอนว่าเจ้า Service นี้มีประโยชน์แน่นอน ในกรณีที่เรามี Controller หลายตัว ไม่ว่าจะ 2 3 หรือมากกว่า เจ้า Service นี้จะมีประโยชน์โดยเป็นตัวกลางในการเก็บเอา Logic ของ controller ที่ต้องเขียนซ้ำ ๆ มาเขียนไว้ที่เดียว และเรียกใช้ผ่านการ Injection แทน . . . มองภาพยากมั้ย ? . . . งั้นมาดูรูปกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UbYKom8FPYd3JP6XXrohew.png" /></figure><p>จะเห็นได้ว่า controller ทั้ง 3 ตัวนั้นจำเป็นต้องใช้โมเดล data ตัวเดียวกันหมด ซึ่งจะเกิดอะไรขึ้นถ้าหากเราไม่มี MyService ตัวนี้ไว้ให้บริการ ? . . . เราจะทำการใส่ code ซ้ำ ๆ มันลงไปใน controller เช่นนั้นเลยรึ ??</p><p>ก็หวังว่าทุกคนจะได้คำตอบจากภาพประกอบตัวอย่างที่ได้มานี้น่ะจ๊ะ . . . แต่ถ้าถามว่าแล้วในบทความนี้ที่เขียนมา Service นั้นได้ประโยชน์อะไร ก็ขอตอบง่าย ๆ เลยว่าไม่มีจ๊ะ . . . แต่ทำมาเพื่อให้ได้เข้าใจกันถ้วนหน้าเก่ียวกับ AngularJS Module Controller Service ตามวัตถุประสงค์เท่านั้น</p><p>เอาล่ะ . . งั้นมาจบบทความนี้ไปพร้อม ๆ กันกับ Review ฉบับเต็มของไฟล์ html js css ของโปรเจ็คนี้กัน . . . บายจ่ะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WeLbdKeQG-e26_hC1Hae1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsoCDspFVz6Yox2kfLqP1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PzTMvf-byfW4BG6RuLZtA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30111d7c8eb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เรามาเขียน Automated Testing แบบ Clean ๆ กันเถอะ]]></title>
            <link>https://medium.com/@neverzero9/%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%A1%E0%B8%B2%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99-robot-automated-%E0%B9%81%E0%B8%9A%E0%B8%9A-clean-%E0%B9%86-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0-665a8843e65b?source=rss-46d76a699bbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/665a8843e65b</guid>
            <category><![CDATA[selenum2library]]></category>
            <category><![CDATA[automated-testing]]></category>
            <category><![CDATA[robot-framework]]></category>
            <dc:creator><![CDATA[Puck]]></dc:creator>
            <pubDate>Thu, 21 Jun 2018 16:12:10 GMT</pubDate>
            <atom:updated>2018-06-22T16:13:03.067Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>ทำความเข้าใจกันก่อน<br> บทความนี้จะไม่ได้ สอน/อธิบาย เกี่ยวกับ Robot Framework แต่อย่างใด แต่เราจะมาพูดถึง Best Practices ในการเขียนเจ้า Robot Test หรือที่ควรจะเรียกก็คือเขียนแบบ Clean Code กัน</li><li>สิ่งที่รู้ควรก่อน อ่านบทความนี้<br> - Robot Framework <br> - Selenum2Library <br>เข้าใจว่าเจ้าสองตัวนี้คืออะไร ใช้ทำอะไร และเคยใช้เจ้าสองตัวนี้หรือเคยลองเล่นมาก่อนน่ะจ๊ะ</li></ul><p>Ok!! พร้อมแล้วเรามาเริ่มทำ Best Practices นี้กันเลย++</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*WaZ22k7548ePtV2zgi938Q.jpeg" /></figure><ul><li>ในบทความนี้เราจะมาทำงาน Robot Test สำหรับเว็บ Priceza แบบง่าย ๆ กัน</li></ul><p>โดยจุดประสงค์ของเจ้า test ตัวนี้จะมีอยู่ว่า<br> 1. Test Url <a href="http://www.priceza.com">www.priceza.com</a> ทำงานได้ปกติ<br> 2. Test Search ค้นหา Product แล้วต้องมี results ออกมา<br> 3. Test Search product with max/min price แล้วต้องได้ results ที่ต้องการออกมา<br>ปล. แต่อย่าลืมไปนะจ๊ะ ว่าในบทความนี้เราจะมาทำ Test แบบ Clean ๆ กัน ไม่ใช่การสอนวิธีติดตั้งใช้งาน หรือแก้ปัญหาใด ๆ</p><p>Setup Projec กัน</p><ul><li>Priceza (Folder Project)<br>| — results (ไว้สำหรับเก็บไฟล์ .robot)<br>| — tests (results จะไว้สำหรับเก็บผลลัพธิ์ที่ได้จากการ Test)<br>| —| — PricezaTest.robot</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4l2UJwsUUabZsJj-8V0PWA.png" /></figure><p>เพิ่ม *** Settings ***</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*zjq5gq7qrichazqWxMjuyw.png" /></figure><p>Documentation สำหรับระบุ Document details ว่าเจ้า .robot ไฟล์นี้ทำหน้าที่เกี่ยวกับอะไร</p><p>ปล. แต่ขอเน้นหน่อย ๆ นะ ว่าเจ้า Document detail นี้ควรที่จะระบุสั้น ๆ ว่า test นี้ทำอะไร ไม่ใช่ทำอย่างไรนะจ๊ะ</p><p>Library เป็นสิ่งที่เราจะขาดไม่ได้เลย กับเจ้า Selenium2Library พระเอกของงาน</p><p>การ Setup โปรเจ็คเสร็จสิ้น แต่ . . . การเทสพึ่งจะเริ่มต้นขึ้นเท่านั้น . . . ต่อซิ รออะไร!!</p><p>มา!! . . . เริ่มกันที่วัตถุประสงค์แรก <br>“1. Test Url <a href="http://www.priceza.com">www.priceza.com</a> ทำงานได้ปกติ”<br>ซึ่งเราต้องการเทสว่าหน้าเว็บเพจนี้ มันทำงานอยู่รึเปล่า แค่นั้นเองแหละจ่ะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVnNE_9NjTgIj0tlUVpY8g.png" /></figure><p>โดยเราจะเริ่มต้นให้ Basic ที่สุดด้วยการ ใส่ Test Case ลงมันไปเลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5KGwLdkUmduWVM5Nzxryw.png" /></figure><p>เมื่อได้ Test Case เพียงพอแล้ว จากนั้นเราก็มารันเจ้าไฟล์ .robot ตัวนี้ผ่าน Folder Priceza Project กัน<br>โดยใช้ Command $ robot -d results tests/PricezaTest.robot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fsmg7fHfDtFYhOOT2F9cgw.png" /></figure><p>Yeahh!! วัตถุประสงค์แรกของเราผ่านไปแล้ว++<br>และตอนนี้เจ้า Test Case ของเราก็ยังคง Clean อยู่ด้วยตัวของมันเอง โดยที่เราไม่จำเป็นต้อง Refactor ใด ๆ<br>ปล. Refactor ในที่นี้หมายการทำให้ Code กระชับ สั้นลง เข้าใจง่ายที่สุดน่ะจ๊ะ เผื่อบางคนอาจจะไม่เข้าใจความหมายกัน</p><p>งั้นเรามาต่อกันที่วัตถุประสงค์ที่สองกันเลยดีกว่า ไม่เสียเวลา<br>“2. Test Search ค้นหา Product แล้วต้องมี results ออกมา“<br>เราต้องการที่จะเทสว่าเมื่อเรา Search แล้วเราจะต้องได้ผลลัพธิ์ออกมาเป็นเว็บเพจ result ที่เราต้องการ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ke-AHOA55z2Hm5Z1bJfGTg.png" /></figure><p>และนี้คือชุดคำสั่ง Test Case ที่เราจะต้องใส่เข้าไป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z4Xf3oM3UINm1WTWGWHwoQ.png" /></figure><p>จากนั้นเราก็รัน command ผ่าน Folder Priceza Project แล้วมาดูผลลัพธิ์กันอีกที<br> $ robot -d results tests/PricezaTest.robot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_74CnvTVOWqek67D03_JsA.png" /></figure><p>Yeahhhh! ผ่านเหมือนเดิมเลย ทำไมมันง่ายเช่นนี้ . . . . แต่เดียวก่อนน่ะ แต่ถ้ากลับไปสังเกตชุดคำสั่ง Test Case ของเราดี ๆ แล้วล่ะก็ . . . .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h6gYFjmLwDN6EqLT4vuPhw.png" /></figure><p>โอ้ววว ไม่นะ ความซ้ำซ้อนของ Code เราได้เริ่มต้นขึ้นแล้ว . . . ไม่สิ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEG9huFG8Y4gScioeDwXCA.png" /></figure><p>โอ้ววว ซ้ำกันเป็นแถวเลยด้วยซ้ำในความเป็นจริง งั้นเราคงต้องมา Refactor Code ของเรากันหน่อยซะแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VphBnuT3nkHUEvrHykqi-A.png" /></figure><p>ในส่วนของการ Open Browser เปิดไปยังหน้าเพจ <a href="http://www.priceza.com">www.priceza.com</a> นั้น เราก็ Refactor โดยการย้ายจาก test case ไปใส่ใน Keyword ซะ โดยตั้งชื่อว่า Open Browser Up แล้วเรียก Keyword นั้นใน test case ของเราแทน ลดความซ้ำซ้อนไปได้อีกหนึ่ง</p><p>ส่วนเจ้าชื่อสินค้า Electric Skateboard ที่เรา Search นั้น เราก็จัดการย้ายมันไปใส่ Variable ซะ จะได้ง่ายเมื่อเราต้องการเปลี่ยนชื่อ สินค้าที่ต้องการค้นหา<br>ปล. เพราะเมื่อเรากด Search ไม่ว่าอะไรไปก็ตามใน Priceza มันจะ return ชื่อสินค้ากลับมาพร้อม String รวมกันเป็นชื่อ Title Page</p><p>เช่น “ ${product} เช็คราคาล่าสุด ราคาถูก ราคาปัจจุบัน”</p><p>Ok!! เมื่อ Refactor กันเสร็จแล้วเราก็มาทำวัตถุประสงค์สุดท้ายกันเถอะ​!!<br>“ 3. Test Search product with max/min price แล้วต้องได้ results ที่ต้องการออก”</p><p>รอช้าอยู่ใยยัดมันเข้าไปเลย!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5QeVQPTCTPqTkp7Uq8bcg.png" /><figcaption>Max Price Test Case</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02HBCLsi6VgHna0ia3i_Rg.png" /><figcaption>Min Price Test Case</figcaption></figure><p>ยัดเข้าไปเสร็จแล้ว ก็ลอง Run เจ้า PricezaTest.robot กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THadgo_9UQkRGlacDt58xw.png" /></figure><p>Yess!++ Run ผ่านแล้วเราก็มา Clean Code ของเราต่อกัน</p><p>เสร็จแล้วเราก็มาเช็ค Code ของเรากันหน่อย ว่ามีอะไรที่มันซ้ำซ้อนบ้าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lt9gRHXTRDRbHqHEtrEOTQ.png" /></figure><p>จะเห็นได้ว่าเจ้า Search Product บลา ๆ ๆ ของเราทั้ง 3 เทสเคสนั้น มี Code ที่ซ้ำกันทุกระเบียดนิ้วอย่างเห็นได้ชัด แต่ เอ… ถ้าดูให้ดี ๆ แล้วล่ะก็</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iQsYFRNBWwIzioCHcAfHXw.png" /></figure><p>โอ้วว จริง ๆ แล้วระหว่าง test case ของเรา Max/Min เคสนี้ เหมือนกันแทบทุกอย่างเลย ต่างกันแค่ value ที่ใส่ลงไปใน Parameter แค่สามค่าเท่านั้น . . . Ok งั้นเรามา Refactor เจ้า Code ของเราทั้งสองเคสนี้กันเลยดีกว่า</p><h3>LET’S DO THIS!!!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*598G-WS1-c2VRhqB8E4dfQ.png" /></figure><p>โดยเมื่อเราทำการ Refactor Code ของเรา ด้วยการย้าย Code ที่ซ้ำซ้อนในกรอบสีม่วง/เขียวไปไว้ใน Keyword และยัด Arguments ใส่เข้าไปใน Keyword &gt;&gt; Max/Min Price เพื่อแยก Test Case ที่ทำงานเหมือนกัน แต่คาดหวังผลลัพธิ์หรือ Variable ที่แตกต่างกัน เราก็จะได้ Code ที่ Clean ขึ้นไปอีกขั้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z95CRbdaLGEZq7HmG6P_sw.png" /></figure><p>และนี้ก็คือโฉมหน้าของเจ้า Test Case เต็ม Version ของเราตามวัตถุประสงค์ทั้งสามข้อ</p><blockquote>1. Test Url <a href="http://www.priceza.com">www.priceza.com</a> ทำงานได้ปกติ<br> 2. Test Search ค้นหา Product แล้วต้องมี results ออกมา<br> 3. Test Search product with max/min price แล้วต้องได้ results ที่ต้องการออกมา</blockquote><p>แต่เดี๋ยวนะ . . . ความจริงแล้ว เราไม่จำเป็นต้องใส่ถึง 4 เทสเคสเลยก็ได้นี้ แค่สองเทสเคส Max/Min เท่านั้นก็เพียงพอแล้วสำหรับ 3 วัตถุประสงค์ของเรา . . .</p><p>จะช้าอยู่ใย ไป Refactor ออกซะซิ!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ge4rNYrVIamXH67j72QvgA.png" /></figure><p>จัดการขยี้เจ้า Code ในกรอบสีแดงออก และ Move เจ้า Code ในกรอบสีเขียวไปไว้ตามลูกศรซะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BtHPDqpGzHyis9wkRDDAmQ.png" /><figcaption>แล้วเราก็จะได้ Code .robot Test ที่สุดแสนจะ Clean มาหนึ่งตัว</figcaption></figure><p>แล้วเราก็จะได้ Code .robot Test ที่สุดแสนจะ Clean มาหนึ่งตัว</p><p>ซึ่งเทคนิคที่เราใช้ใน ณ ที่นี้ มีแค่การแทนค่า Variable กับรวบโค้ดซ้ำยัดลงไปใน Keyword เท่านั้น แค่เท่านี้ Code ของเราก็สุดแสนจะสั้นและสวยงามกันแล้วว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*cc6KdAGQLLAsBwCxWXWQOA.png" /></figure><blockquote>อย่าปล่อยให้การเขียน Code ของคุณเป็นการ Encrypt ไปโดยปริยาย . . . . . . . . น่ะจ๊ะ</blockquote><p>Etc. เพิ่มเติม สำหรับคนอยากต่อ . . .<br><a href="https://github.com/robotframework/HowToWriteGoodTestCases/blob/master/HowToWriteGoodTestCases.rst">https://github.com/robotframework/HowToWriteGoodTestCases/blob/master/HowToWriteGoodTestCases.rst</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=665a8843e65b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>