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清單。
https://loveflover.ru — сайт посвященный комнатным растениям. Предлагает подробные статьи о выборе, выращивании и уходе за различными видами комнатных растений. Здесь можно найти полезные советы по созданию зелёного уголка в доме, руководства по декору и решению распространённых проблем, а также информацию о подходящих горшках и удобрениях. Платформа помогает создавать уютную атмосферу и гармонию в интерьере с помощью растений.
Хотите сделать в квартире ремонт? Тогда советуем вам посетить сайт https://stroyka-gid.ru, где вы найдете всю необходимую информацию по строительству и ремонту.
Latest news and analytics of the Premier League https://premier-league.com.az. Detailed descriptions of matches, team statistics and the most interesting football events. EPL Azerbaijan is the best place for football fans.
The most popular sports site https://sports.com.az of Azerbaijan, where the latest sports news, forecasts and analysis are collected.
Latest news about games for Android https://android-games.com.az, reviews and daily updates. Read now and get the latest information on the most exciting games
Check out the latest news, guides and in-depth reviews of the available options for playing Minecraft Az https://minecraft.com.az. Find the latest information about Minecraft Download, Pocket Edition and Bedrock Edition.
obviously like your web site but you need to check the spelling on quite a few of your posts. Many of them are rife with spelling issues and I find it very bothersome to tell the truth nevertheless I?ll certainly come back again.
The Dota 2 website https://dota2.com.az Azerbaijan provides the most detailed information about the latest game updates, tournaments and upcoming events. We have all the winning tactics, secrets and important guides.
Play PUBG Mobile https://pubg-mobile.com.az an exciting world of high-quality mobile battle royale. Unique maps, strategies and intense combat await you in this exciting mobile version of the popular game.
Сантехник — вызов сантехника на дом в Москве и Московской области в удобное для вас время.
Каталог рейтингов хостингов https://pro-hosting.tech на любой вкус и под любые, даже самые сложные, задачи.
augmentin 875 coupon
Discover the fascinating world of online games with GameHub Azerbaijan https://online-game.com.az. Get the latest news, reviews and tips for your favorite games. Join our gaming community today!
The latest top football news https://futbol.com.az today. Interviews with football players, online broadcasts and match results, analytics and football forecasts, photos and videos.
Latest news and details about the NBA in Azerbaijan https://nba.com.az. Hot events, player transfers and the most interesting events. Explore the world of the NBA with us.
Top sports news https://idman-azerbaycan.com.az photos and blogs from experts and famous athletes, as well as statistics and information about matches of leading championships.
buy cheap lasix without prescription
diflucan 150 otc
We would also like to state that most individuals who find themselves with no health insurance are generally students, self-employed and those that are out of work. More than half from the uninsured are really under the age of 35. They do not feel they are in need of health insurance as they are young in addition to healthy. Their income is frequently spent on real estate, food, along with entertainment. Some people that do represent the working class either entire or part-time are not presented insurance by their jobs so they head out without because of the rising cost of health insurance in the United States. Thanks for the thoughts you write about through this blog.
advair diskus 100
whoah tһis weblog is fantastic i lіke reading your articles.
Keep up the gгeat ᴡork! You understand, а lott оf people ɑгe hunting
around for this info, you coսld aid tһem greatly.
Ꭺlso vvisit myy site … Gopek178 Legal
buy spironolactone 25mg for sale – epitol over the counter revia sale
baclofen brand name in usa
100 amoxicillin 500 mg
baclofen discount
advair diskus 550
cytoxan brand – buy strattera 25mg sale order trimetazidine online cheap
Профессиональные seo https://seo-optimizaciya-kazan.ru услуги для максимизации онлайн-видимости вашего бизнеса. Наши эксперты проведут глубокий анализ сайта, оптимизируют контент и структуру, улучшат технические аспекты и разработают индивидуальные стратегии продвижения.
150 mg diflucan
With every little thing which seems to be building inside this subject matter, all your opinions tend to be quite stimulating. On the other hand, I beg your pardon, because I do not subscribe to your entire strategy, all be it exhilarating none the less. It would seem to everyone that your remarks are actually not entirely justified and in fact you are generally your self not even fully confident of your assertion. In any event I did take pleasure in reading through it.