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清單。
I do not even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you are going to a famous blogger if you are not already 😉 Cheers!
I had fun reading this post. I want to see more on this subject.. Gives Thanks for writing this nice article.. Anyway, I’m going to subscribe to your rss and I wish you write great articles again soon.
https://datingtopreview.online/# internet dating service
buy ceftin 250mg without prescription careprost medication oral robaxin
dating service tender dating site
https://datingtopreview.com/# local personal ads
viagra price where can i buy viagra over the counter
Thank you a lot for sharing this with all folks you actually recognize what you’re speaking about! Bookmarked. Please additionally visit my site =). We can have a hyperlink trade contract among us!
order generic sildenafil 50mg buy nolvadex 10mg for sale buy rhinocort generic
canadian pharmacy prices precription drugs from canada
https://pharmacywithoutprescription.life/# canadian pharmacy discount code
https://pharmacywithoutprescription.life/# cheapest pharmacy for prescriptions without insurance
Awesome post. It’s so good to see someone taking the time to share this information
buy cephalexin 125mg online cheap cleocin 300mg purchase erythromycin online cheap
Ꮃhat’s up, all is going well here and ofcourse еvery onee iѕ sharing іnformation, that’s genuinely
excellent, ҝeep սp writing.
mʏ web blog :: cara menambah viewers tiktok
viagra vs cialis As new therapies are developed, they can open doors to other drugs and procedures that may be even more effective
https://canadian-pharmacy.shop/# canadian pharmacy viagra 100mg
online canadian pharmacy coupon online pharmacy prescription
https://prednisone20mg.icu/# 1250 mg prednisone
prednisone 1 tablet prednisone 10mg cost
Cortisol is a hormone that helps to promote energy and suppress the immune system buy cialis without prescription
Türkiye Haberleri
https://buytadalafil.icu/# tadalafil generic over the counter
college application essay service
custom essays
cheap custom essay papers
https://amoxil.best/# generic amoxicillin cost
best online essay writers
do my essay for me cheap
cheap essays for sale
custom written essays
essay writer reviews
essay writing services online
https://amoxil.best/# amoxicillin medicine
doxycycline without a prescription buy amoxicillin online no prescription
augmentin 375mg ca sulfamethoxazole generic bactrim online order