AngularJS – Directive & Filter 介紹篇
為了方便文章閱讀,本篇將filter翻譯成過濾器、directive翻譯成指示指令
在看過前幾篇的AngularJS的教學後,我們對AngularJS的開發應該有了基本的認識,針對HTML文件中我們的操作有:
針對頁面引入應用程式模組
<html ng-app="store">
針對頁面引入控制器
<body ng-controller="StoreController as store">
針對頁面去顯示或隱藏元素
<h1 ng-show="name">Hello, {{ name }} !</h1>
針對大量的資料設定重複的區域
<li ng-repeat="product in store.products">{{ product.name }}</li>
接下來針對過濾器來介紹,依下圖所示產品價格的部分,有的是有小數點有的沒有,會造成頁面在資料呈現上的參差不齊。
若我們在該表達式(expression)加上一條直線(pipe),在直線後面可以加入一些過濾器,本範例加入的是貨幣格式的過濾器,當加入後價格在頁面上顯示的格式,就會自動加上了$符號和兩位數的小數點。
我們也可以在過濾器後面利用冒號再加上一些選項,讓呈現的資料更不同,例如下圖中date格式中是以「月/日/年 @ 時:分AM」這樣的方式顯示,而除了貨幣currency、日期date的過濾器之外,還包含有大小寫轉換的uppercase、lowercase、字數也可以當成資料呈現筆數的limitTo、另外還有可以針對重複性的資料進行排序的orderBy,大概的使用方式可以參考下圖,或是在JS Bin看看馬老師製作的案例。
另外關於指示指令部分,在這次的案例上我們加上產品的圖片,圖片的部分有兩種,一個是大圖;另一個是產品的縮圖,也因為有兩種不同的資料,要注意他被加在數列裡面的方式。
在頁面上顯示圖片的方式要注意不是用src的屬性去呈現,而是需要用ng-src這個屬性,加上圖片欄位的表達式即可,在JS Bin上面觀賞本案例程式碼。
※以上截圖部分為AngularJS官方教學視訊,另有filter指令介紹的專頁和所有filter清單。
can i buy cialis online Braintree also has broad international reach, with merchants in 40 countries accepting payments in 130 currencies
https://amoxil.best/# amoxicillin buy canada
https://buytadalafil.icu/# tadalafil best price
where can i buy zithromax capsules generic zithromax india
https://amoxil.best/# amoxicillin 500mg prescription
generic ampicillin 500mg cost ciprofloxacin 1000mg order metronidazole sale
cheap essay papers
mba essay help
helping others essays
my custom essay
top essay editing service
cheap essays to buy
https://buytadalafil.icu/# generic tadalafil india
Glad to be one of many visitants on this amazing site : D.
valacyclovir 500mg uk purchase diflucan generic diflucan over the counter
This is very attention-grabbing, You’re an overly skilled blogger. I have joined your feed and look ahead to searching for more of your magnificent post. Additionally, I have shared your web site in my social networks!
college essay review services
cheapest essays writing services
mba application essay writing service
ondansetron cost brand spironolactone 100mg zocor 10mg tablet
best essay writing
essay help introduction
professional essay writing services
fiverr.com
Thank you so much for sharing this wonderful post with us.
Olefsky JM, Farquhar JW, Reaven GM lasix hypokalemia
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here It’s always nice when you can not only be informed, but also entertained I’m sure you had fun writing this article.
lasix dosage Acteoside ACT, a major component and lipase inhibitor from the Chinese tea Ligustrum purpurascens kudingcha, has b
Your article has answered the question I was wondering about! I would like to write a thesis on this subject, but I would like you to give your opinion once 😀 slotsite
https://buytadalafil.icu/# tadalafil for sale from india
websites for essay writing
college admissions essay help
i need help writing my essay
how to be a good essay writer
pay you to write my essay
best custom essay sites
essay on old custom
urgent custom essays
essay help toronto
There іs certainly a great deal to learn about this subject.
I liкe all tһе рoints you’ve maɗe.
My blog: jasa subscriber dan jam tayang
Apropos signatures, homeopathic parallels, etc does lasix lower potassium
national junior honor society essay help
buy essays online cheap
help write essay for me
meloxicam 15mg ca tamsulosin ca order flomax 0.4mg online cheap
english essay helper
college essay writers block
essay conclusion help