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清單。
http://kamagra.win/# super kamagra
happy family drugstore
http://kamagra.win/# buy kamagra online usa
https://levitrav.store/# Buy Vardenafil 20mg
Cialis 20mg price: cialist.pro – cialis generic
Levitra online pharmacy Vardenafil buy online Levitra 10 mg buy online
Cheap Levitra online Buy Vardenafil 20mg Levitra tablet price
http://viagras.online/# cheapest viagra
https://levitrav.store/# Buy Vardenafil online
cheapest cialis: cialist.pro – Cialis without a doctor prescription
onlinecanadianpharmacy
Buy Tadalafil 20mg: buy cialis online – Cheap Cialis
Hi cloudlab.tw
We noticed your website cloudlab.tw is only listed in 9/2,500 directories.
We have a service that lists your company in all the directories globally.
It supports all countries, all services, to boost your SEO and get you those high quality back links that directories offer.
We have a promo running for a one time fee of $99
Visit us on https://cloudlab.companyregistar.org/cloudlab.tw to get listed.
лазерная очистка от ржавчины http://www.apparaty-lazernoy-ochistki.ru/ .
Buy Cenforce 100mg Online: Buy Cenforce 100mg Online – Purchase Cenforce Online
http://kamagra.win/# Kamagra Oral Jelly
п»їcialis generic: Generic Tadalafil 20mg price – Cheap Cialis
Cenforce 150 mg online: Cenforce 150 mg online – Purchase Cenforce Online
india cialis online
buy cytotec over the counter buy cytotec pills online cheap cytotec pills buy online
prescription for cialis
п»їcytotec pills online purchase cytotec buy cytotec online
ciprofloxacin order online: ciprofloxacin mail online – ciprofloxacin 500mg buy online
http://finasteride.store/# propecia
cost generic propecia: cheap propecia without prescription – buying propecia for sale
https://lisinopril.network/# lisinopril 1.25 mg
https://lisinopril.network/# cost for 20 mg lisinopril
https://nolvadex.life/# tamoxifen vs raloxifene
tamoxifen 20 mg: dcis tamoxifen – tamoxifen and antidepressants
lisinopril 20mg online lisinopril cost 5mg on line order lisinopril 20mg