AngularJS – Controller 介紹篇
繼續AngularJS的介紹,接下來我們看看controller的應用,以商品介紹的頁面為例,來看看這些資料要如何呈現在頁面上,想要呈現的資料有產品名稱、價格以及描述。
為了方便文章閱讀,本篇將application翻譯成應用程式;controller翻譯成控制器
控制器負責定義函數和值來決定整個應用程式的行為,同樣我們把Javascript和HTML分開來開發,在app.js內定義應用程式名稱和控制器的名稱、函數與值,在這次的案例中也提到利用(function(){})()包裝整個javascript是一種好習慣,有關於函式的基本觀念,大家可以閱讀一下這篇文章,介紹的還蠻詳細的!包裝部分的概念可參考其中介紹的立即函示(IIFE – Immediately Invoked Function Expression)。
定義好之後可以開始定義該控制器內的值,其中this.product=gem的意思是指未來在輸出時可以利用product.name去取得Dodecahedron;product.price去取得2.95…等等。
接下來就是把這些值顯示在網頁上,首先可以在div標籤內加上ng-controller=”StoreController as store”的屬性,其中ng-controller是去指定StoreController為該div內的控制器名稱;store是別名(類似綽號)未來呼叫store時就是在呼叫StoreController這個控制器。
在HTML標籤內開始輸出該控制器內的值,分別是:store.product.name、store.product.price、store.product.description三個項目,而在頁面上就會看到這三個值被顯示出來了。
需要注意的是,如果我們把輸出值部分的程式碼放在div外側的話,會沒有辦法順利的顯示值,因為我們的控制器是指定於div標籤內,離開了div標籤就無法取得該控制器了。
本篇的教學就到這邊,大家也可以透過JS Bin來測試或閱讀本次案例的程式碼。
<!DOCTYPE html> <html ng-app="store"> <head> <meta name="description" content="controllerExample"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <meta charset="utf-8"> <title>controllerExample</title> </head> <body> <div ng-controller="StoreController as store"> <h1>{{ store.product.name }}</h1> <h2>{{ store.product.price }}</h2> <p>{{ store.product.description }}</p> </div> </body> </html> (function(){ var app = angular.module('store',[]); app.controller('StoreController',function(){ this.product = item; }); var item = { name:"馬老師雲端研究室 滑鼠墊", price:"350", description:"有些人認為滑鼠墊就只是種簡單的產品。無非是將滑鼠放於上方並將之滑來拖去。 “表面”上來說確實如此(一語雙關)。但實際上,製造能帶來卓越遊戲體驗的滑鼠墊卻需要結合眾多科學、技術和工藝。身為遊戲滑鼠技術的世界領先者,對如何使滑鼠感測器高效運作我們獨樹一幟。運用專門知識來製造適合的滑鼠墊表面,讓滑鼠感測器得以作出高效而精確的反應。", }; })();
※以上截圖部分為AngularJS官方教學視訊,另有控制器指令介紹的專頁。
15 Top Pinterest Boards From All Time About
Zeus Hades Oscarreys
15 Unquestionably Good Reasons To Be Loving
Demo Slot Pragmatic Play Sweet Bonanza trik Sweet Bonanza hari Ini
Link pyramid, tier 1, tier 2, tier 3
Primary – 500 links with integration contained in compositions on content sites
Level 2 – 3000 web address Forwarded connections
Tier 3 – 20000 connections combination, feedback, entries
Utilizing a link pyramid is useful for search engines.
Necessitate:
One hyperlink to the website.
Search Terms.
Correct when 1 query term from the website heading.
Note the supplementary functionality!
Crucial! Top connections do not overlap with Secondary and Tertiary-tier hyperlinks
A link structure is a instrument for enhancing the circulation and inbound links of a digital property or social media platform
5 Killer Queora Answers On Door Fitters Manchester window fitters manchester [Nelle]
The Top Companies Not To Be Follow In The Best Side
By Side Fridge Freezer Industry 36035372.xyz, Selena,
9 Lessons Your Parents Teach You About Play Slots Online kaymell (Lawanna)
20 Reasons To Believe Shop Online Will Never Be Forgotten where can i shop online with google pay (http://jejucordelia.Com)
The Best Adult Toys For Men Tricks To Transform Your Life
best Adult toys for men
10 Signs To Watch For To Look For A New Retro Fridge Freezer
Blue cheap retro Fridge freezer Uk
15 Unexpected Facts About Adult Store Near Me The Words You’ve Never Learned male adult sex toys (John)
10 Inspirational Graphics About Boat Accident Legal Boat accident law firms
How Much Do Malpractice Claim Experts Make? malpractice
lawsuit (Lane)
10 Websites To Aid You To Become A Proficient In Slot Demo Pragmatic Pragmatic play demo
The Top Reasons Why People Succeed In The Cheap Double Stroller Industry double pram buggy (Zachery)
A Step-By-Step Guide To Selecting The Right Wall Mount Electric Fireplace 0773781
10 Websites To Help You Develop Your Knowledge About Retro
Fridge Freezers Uk Fridge freezer retro
11 Ways To Totally Defy Your Erb’s Palsy Attorneys erb’s Palsy lawsuits
10 Misconceptions That Your Boss May Have About Double
Glazing Companies Near Me Glaziers
Your Worst Nightmare About Metal Anal Butt Plug It’s Coming To Life small vibrating Anal plug
The No. Question That Everyone In Bunk Bed Shop Should Be Able Answer eddafay
Link pyramid, tier 1, tier 2, tier 3
Level 1 – 500 links with integration within compositions on writing domains
Secondary – 3000 link +Redirect connections
Level 3 – 20000 hyperlinks blend, feedback, articles
Using a link hierarchy is useful for search engines.
Require:
One hyperlink to the website.
Keywords.
Correct when 1 keyword from the resource subject.
Highlight the supplementary offering!
Crucial! Top links do not intersect with Tier 2 and Tertiary-rank connections
A link hierarchy is a instrument for increasing the flow and inbound links of a digital property or social network
Who’s The World’s Top Expert On Window Repair Near? Upvc Window Repairs
24-Hours To Improve Coffee Machine Dolce Gusto Coffee machine For latte
See What Google Shopping – Shop Online Compare Prices Tricks
The Celebs Are Utilizing google shopping – shop online compare prices (Nola)
Lock Smith Car Tools To Improve Your Everyday Lifethe Only Lock Smith Car Trick That Everyone
Should Be Able To lock smith car
What Is Self-Emptying Robot Vacuum And Why You Should Care what is the best self emptying robot vacuum
สวัสดีค่ะ! การเล่น ebet เป็นผู้ให้บริการเกมออนไลน์ที่ได้รับความนิยมอย่างแพร่หลายในวงการพนันคาสิโนออนไลน์ สล็อต ebet เป็นหนึ่งในเกมที่มีความน่าสนใจจาก
ebet ที่คนเล่นสามารถเพลิดเพลินไปกับสล็อตที่กราฟิกสวยงามและเสียงที่สมจริง อีกทั้งยังมีบาคาร่าออนไลน์จาก ebet ที่น่าสนใจมากเช่นกัน หากคุณต้องการพบกับประสบการณ์การเล่นคาสิโนที่ไม่ธรรมดา คุณสามารถเข้าสู่ casino
ebet และเล่นเกมต่างๆได้อย่างสบายใจและปลอดภัยและปราศจากอันตราย ด้วยความสำคัญที่ผู้ให้บริการ ebet ให้กับความพึงพอใจของผู้เล่น จึงมีเกมบาคาร่าจาก ebet ที่มีคุณภาพและรูปแบบการเล่นที่ให้ความบันเทิงแบบแท้จริง อย่างที่คุณถามว่า
ebet gaming คืออะไร ก็คือผู้ให้บริการเกมคาสิโนออนไลน์ที่มีชื่อเสียงและได้รับความนิยมจากผู้เล่นหลายๆ คนค่ะ
Feel free to visit my web site เว็บคาสิโนออนไลน์ที่ดีที่สุดในไทย
How To Create Successful Vauxhall Car Key Tutorials
On Home New vauxhall astra key
массажистка рядом со мной индивидуалки москвы
проститутки люберцы проститутки азиатки