AngularJS – Directive 介紹篇
接續前面提到的關於產品展示頁面的製作,我們在HTML文件上面加入一個Add to Cart的按鈕,但是希望這個按鈕可以有條件性的顯示或隱藏,我們可以在該按鈕的HTML標籤中加入ng-show=”store.product.canPurchase”的屬性,這個屬性會去判斷在gem數列中canPurchase中的值是否為true,若不是則該按鈕不顯示於畫面上,反之則會顯示加入購物車(Add to Cart)的按鈕。
在這個案例中canPurchase就算是在數列中的顯示參數,其實這個參數並不是一定要叫canPurchase這個名稱,可以自行決定名稱,例如在馬老師製作的案例中,我就是利用buttonShow這樣的參數名稱,大家也可以在JS Bin上面看看這個案例的程式碼。
<!DOCTYPE html> <html ng-app="store"> <head> <meta name="description" content="AngularJS directivesExample 1"> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script> <meta charset="utf-8"> <title>AngularJS directivesExample 1</title> </head> <body> <div ng-controller="StoreController as store"> <h1>{{ store.product.name }}</h1> <h2>NT${{ store.product.price }}</h2> <p>{{ store.product.description }}</p> <button ng-show="store.product.buttonShow">加入購物車</button> </div> </body> </html> (function(){ var app = angular.module('store',[]); app.controller('StoreController',function(){ this.product = item; }); var item = { name:"馬老師雲端研究室 滑鼠墊", price:"350", description:"有些人認為滑鼠墊就只是種簡單的產品。無非是將滑鼠放於上方並將之滑來拖去。 “表面”上來說確實如此(一語雙關)。但實際上,製造能帶來卓越遊戲體驗的滑鼠墊卻需要結合眾多科學、技術和工藝。身為遊戲滑鼠技術的世界領先者,對如何使滑鼠感測器高效運作我們獨樹一幟。運用專門知識來製造適合的滑鼠墊表面,讓滑鼠感測器得以作出高效而精確的反應。", buttonShow: false }; })();
另外還有一種資料顯示的手法,我們可以在gem數列中另外加入soldOut這個參數,而在div的HTML標籤中加入ng-show=”!store.product.soldOut”這樣的屬性,其中驚嘆號指的是不等於,所以這個屬性的意思即是當soldOut參數不等於true的時候要隱藏該div,也就是會隱藏所有的商品資訊。
不過這樣的表達方式並不是很直接,必須要做邏輯上的轉換,因為條件式是soldOut不等於true就顯示該商品,不是很容易搞懂,所以同樣的案例我們可以把HTML中的標籤的屬性改成ng-hide=”store.product.soldOut”,這樣一來我們只需要去看soldOut參數中的值是true或是false,如果賣完就不顯示;沒賣完就顯示,這是一個比較直覺的方法,透過JS Bin觀賞本案例的原始碼。
接下來看多項商品的製作方式,首先必須了解如何在Javascript的數列中加入多項商品的資料。
輸入了以上數列的資料後,在HTML的頁面上可以依下圖的方式呈現出多重商品的資訊,不過從以下的呈現方式可以看的出來,如果商品數量不僅僅是只有兩項,那頁面上面的HTML標籤就會過於複雜,所以下面的方法僅僅是讓大家了解邏輯的部分。
實際上呈現的方式可以參考下圖,是不是簡單多了,在JS Bin上面觀看。
接下來幫大家整理目前講解到的一些AngularJS的專有名稱說明:
- Directives(指示) – 在HTML中觸發Javascript行為的參數。
- Modules(模組) – 定義我們的應用程式。
- Controllers(控制器) – 定義我們應用程式該如運作。
- Expressions(表達式) – 我們的資料該如何的顯示在頁面上。
※以上截圖部分為AngularJS官方教學視訊,另有directive指令介紹的專頁。
Bienvenue sur notre blog, votre espace ultime pour les infos sur les stars africaines du monde des canaux mediatiques et des emissions de realites televisees https://mediaeventhub.africa/ ! Des mouvements recents dans l’industrie du spectacle africain aux commerages les plus epices sur les vedettes, nous vous informerons de toutes les nouvelles fascinantes a travers le Afrique. Cela inclut les partenariats musicaux inedites, de moments palpitants dans les emissions de tele-realite, ou de itineraires de vie emouvants de vos stars preferees, nous tracons tout. La scene du divertissement en Afrique foisonne de talents, et notre blog est la pour vous connecter aux figures qui modelent l’industrie.
Les emissions de tele-realite africaines ont saisi le monde, exposant la multiplicite culturelle, la innovation et l’veracite uniques du sol africain. Des emissions comme « Grand Frere Naija », « Les Real Housewives de Lagos » et « Tentations Afrique du Sud » continuent de captiver des publics massives, eveillant des debats et seduisant des fans bien au-dela de l’Afrique. Nous explorons dans les drames, les relations et les moments inoubliables qui font de ces shows des essentiels a la tele. Notre blog ne se restreint pas a commenter stars, mais analyse le role culturel de ces series, montrant le poids grandissant de la mode populaire africaine a l’echelle planetaire.
Notre blog celebre egalement les personnes du monde mediatique et les jeunes prodiges qui font parler d’eux en Afrique. Des comediens brillants aux animateurs populaires, en considerant aussi les leaders d’opinion sur les sites de reseautage, nous mettons a l’honneur les performances de ceux qui reinventent le show business sur le continent. Cela comprend des actes distingues dans les cinema de Nollywood, des participations remarquables dans des projets globaux ou des prises de position fortes dans des videoclips, nous vous presentons des interviews exclusives et des chroniques qui se cachent derriere la notoriete. Vous trouverez des focus de legendes africaines comme Burna Boy, qui ont non seulement conquis les spectateurs du continent, mais aussi atteint une reconnaissance mondiale.
Restez connectes avec nous pour les actualites a chaud et scoops exclusifs sur vos personnalites preferees d’Afrique. Notre blog est un espace pour les passionnes de divertissement qui souhaitent rester a jour avec les scandales des celebrites, les programmes recents et les mouvements artistiques qui influencent l’industrie. Tant pour un un fan passionne de la culture populaire africaine ou un lecteur occasionnel des dernieres nouvelles du divertissement, notre blog vous offre de vous garder au courant, amuser et motive par le milieu en ebullition des plateformes mediatiques et shows de realite televisee en Afrique.
Table 3 summarises the relationship between tumourstage and groups of symptoms not shown if less thanten patients were affected.
you get the best price when you where can i buy stromectol and save their dollars.
Symptoms may include memory loss, confusion, personality changes, and difficulty with normal activities like eating or dressing.
For more advanced stages of cervical cancer, the uterus may need to be removed with a simple hysterectomy.
Can I expect more discounts if I buy stromectol 3mg cost includes information. See the ED natural treatment options.|
There is also a small chance that women who survive many years after radiation therapy will develop a second malignancy in the radiated area.
Appreciate it for this grand post, I am glad I noticed this website on yahoo.
Your style is very unique compared to other people I have read stuff from. Thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this page.
order mobic – mobic 7.5mg us ketorolac without prescription
I’ve recently started a site, the information you offer on this web site has helped me greatly. Thank you for all of your time & work.
casibom giris adresi: casibom – casibom giris
casibom giris adresi
Отличный сайт! Всем рекомендую обращаться именно сюда!Реабилитационный центр для алкоголиков Киев
Way cool! Some very valid points! I appreciate you writing this write-up plus the rest of the site is really good.
Рекомендую именно этот Реабилитационный центр для наркоманов Киев
you are in point of fact a good webmaster. The web site loading pace is incredible. It seems that you are doing any unique trick. Also, The contents are masterpiece. you’ve done a excellent job in this topic!
order baclofen 25mg online – piroxicam for sale online buy feldene sale
Рекомендую именно этот Реабилитационный центр Киев
In most cases, the operation is done before the appendix perforates.
Everyone can afford to ivermectin 8000 mcg from sites that don’t post info about their company.
Types Over 90 percent of cervical carcinomas start in the surface cells lining the cervix and are called squamous cell carcinoma.
Отличный сайт! Всем рекомендую!салон оптики
Отличный сайт! Всем рекомендую!очки купить в Москве
I resonate deeply with your conclusions.오피
Excellent article. It’s extremely clear and packed with useful information. Thanks for providing this content.
Aw, it was a really good post. In concept I must put in writing similar to this additionally – spending time and actual effort to manufacture a excellent article… but exactly what do I say… I procrastinate alot and no means find a way to go carried out.
Wow! Thank you! I always wanted to write on my website something like that. Can I implement a fragment of your post to my site?
Отличный сайт! Всем рекомендую!оптика Москва
I appreciate the clarity of your explanations.오피
An impressive share! I’ve just forwarded this onto a co-worker who was doing a little research on this. And he actually bought me lunch due to the fact that I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending the time to discuss this topic here on your website.
Thank you for the sensible critique. Me and my neighbor were just preparing to do a little research on this. We got a grab a book from our local library but I think I learned more from this post. I’m very glad to see such wonderful info being shared freely out there.
I just could not depart your web site prior to suggesting that I really loved the standard info a person supply in your guests? Is going to be again steadily to check out new posts
Отличный сайт! Всем рекомендую!слив курсов.net
This is wonderful! Packed with helpful information and highly well-written. Thank you for providing this.
casino en ligne…[…]the time to read or visit the content or sites we have linked to below the[…] w?casino en ligne france…
Wonderful article. It’s very articulate and full of useful information. Thanks for offering this post.