AngularJS – Tab 介紹篇

為了方便文章閱讀,本篇將Tab翻譯成頁籤

這個案例的複雜度會比較前面高一些,因為它不僅僅是使用我們一直提到的AngularJS,為了要製作頁面上面的一些互動效果,還加入了Bootstrape這個通常被用來當RWD的框架,不過也僅僅是套用了幾個類別,所以大家也不用太擔心,接下來我們先看一下這個案例最後希望要達成的效果頁面

在看過了目標頁面後,我們先來了解一下需要怎麼樣架構我們的HTML,首先是CSS和Javascript的引入,分別是AngularJS、jQuery、Bootstrap CSS以及Javascript:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

在HTML文件中,必須有項目清單標籤ul、li,而在ul標籤中需套用nav nav-pills這兩個css類別,這兩個類別是由Bootstrape的css所提供的,li標籤是包覆著超連結的a標籤,下圖案例是希望可以產生三個頁籤。

AngularJS Part5 Slide1
AngularJS Part5 Slide1

在a標籤中加入ng-click=”tab = 1″、ng-click=”tab = 2″、ng-click=”tab = 3″去設定當使用者按下連結後tab變數會隨著變化,另外為了方便觀察是否成功,在頁面上利用表達式將tab變數顯示出來。

AngularJS Part5 Slide1
AngularJS Part5 Slide2

若一切順利,在我們按下不同的頁籤連結時,畫面上應該會有數字上面的變化。

AngularJS Part5 Slide3
AngularJS Part5 Slide3
AngularJS Part5 Slide4
AngularJS Part5 Slide4

接下來開始製作點選頁籤後的內容頁面,同樣的內容頁面也應該有三個才對,在HTML中產生三個div,其中套用Bootstrape所提供的CSS panel類別,div的內容部分可依照需求置入。

AngularJS Part5 Slide5
AngularJS Part5 Slide5

在div中利用ng-show去判斷tab變數的值來切換顯示。

AngularJS Part5 Slide6
AngularJS Part5 Slide6

完成後,在我們點選不同的連結時,內容的部分也應該會隨著變動。

AngularJS Part5 Slide7
AngularJS Part5 Slide7

接下來我們在section標籤中設定ng-init=”tab=1″的屬性來決定tab變數的初始值。

AngularJS Part5 Slide8
AngularJS Part5 Slide8

接下來在li內新增ng-class的屬性,依tab變數的值來切換active的CSS屬性(該屬性由Bootstrape提供樣式),其中三個連續的等號是判斷該變數與值完全相同的意思。

AngularJS Part5 Slide9
AngularJS Part5 Slide9

這個動作的目的是希望當網友點選之後,可以如下圖所示,清楚的標示目前頁面上所顯示的是第幾個項目。

AngularJS Part5 Slide10
AngularJS Part5 Slide10

到目前為止,大概就完成了我們希望呈現的頁籤效果,大家可以透過JS Bin來測試看看到目前為止的程式碼。

<!DOCTYPE html>
<html ng-app>
<head>
<meta name="description" content="AngularJS Tabs Example 1">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
  <meta charset="utf-8">
  <title>AngularJS Tabs Example 1</title>
</head>
<body>
  <section ng-init="tab=1">
    
    <ul class="nav nav-pills">
      <li ng-class="{ active: tab===1 }">
        <a href="" ng-click="tab=1">滑鼠墊</a>
      </li>
      <li ng-class="{ active: tab===2 }">
        <a href="" ng-click="tab=2">馬克杯</a>
      </li>
      <li ng-class="{ active: tab===3 }">
        <a href="" ng-click="tab=3">杯墊</a>
      </li>
    </ul>
    
    <div class="panel" ng-show="tab===1">
      <h4>馬老師雲端研究室 滑鼠墊</h4>
      <p>產品介紹...</p>
    </div>
    <div class="panel" ng-show="tab===2">
      <h4>馬老師雲端研究室 馬克杯</h4>
      <p>產品介紹...</p>
    </div>
    <div class="panel" ng-show="tab===3">
      <h4>馬老師雲端研究室 杯墊</h4>
      <p>產品介紹...</p>
    </div>
  
  </section>
</body>
</html>

在看完了上面的案例之後,我們可以觀察到程式邏輯判斷的部分都是直接撰寫在HTML頁面上,那如果我們要把邏輯判斷的部分從HTML拆開寫到Javascript檔又應該要如何處理呢?首先,不用說的當然是必須要有應用程式的建立以及控制器囉!下圖中我們開始新增控制器,並且在section標籤中,輸入ng-controller=”panelController as panel”的屬性,相信在看了前幾篇教學的同學們對於這樣的項目是再熟悉不過了!接下來在控制器中,決定tab變數的初始值,就可以把原來的ng-init屬性刪除了。

AngularJS Part5 Slide11
AngularJS Part5 Slide11

在ng-click後去執行控制器中的selectTab函數,並且針對該函數帶入不同的值,利用帶入的值來改變tab變數值。

AngularJS Part5 Slide12
AngularJS Part5 Slide12

在ng-click後去執行控制器中的isSelected函數,也帶出不同的值給函數,讓函數可以回傳tab===1或2、3這樣的內容給ng-show使用。

AngularJS Part5 Slide13
AngularJS Part5 Slide13

這樣一來我們邏輯判斷的部分就會和網頁內容有所區隔,大家也可以透過JS Bin來測試這樣的程式結構。

<!DOCTYPE html>
<html ng-app="store">
<head>
<meta name="description" content="AngularJS Tabs Example 2">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//code.jquery.com/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
  <meta charset="utf-8">
  <title>AngularJS Tabs Example 2</title>
</head>
<body>
  <section ng-controller="PanelController as panel">
    <ul class="nav nav-pills">
      <li ng-class="{ active: panel.isSelected(1) }">
        <a href="" ng-click="panel.selectTab(1)">滑鼠墊</a>
      </li>
      <li ng-class="{ active: panel.isSelected(2) }">
        <a href="" ng-click="panel.selectTab(2)">馬克杯</a>
      </li>
      <li ng-class="{ active: panel.isSelected(3) }">
        <a href="" ng-click="panel.selectTab(3)">杯墊</a>
      </li>
    </ul>
    <div class="panel" ng-show="panel.isSelected(1)">
      <h4>馬老師雲端研究室 滑鼠墊</h4>
      <p>產品介紹...</p>
    </div>
    <div class="panel" ng-show="panel.isSelected(2)">
      <h4>馬老師雲端研究室 馬克杯</h4>
      <p>產品介紹...</p>
    </div>
    <div class="panel" ng-show="panel.isSelected(3)">
      <h4>馬老師雲端研究室 杯墊</h4>
      <p>產品介紹...</p>
    </div>
  </section>
</body>
</html>
(function(){
  var app = angular.module('store', []);
  
  app.controller('PanelController', function(){
    this.tab = 1;
    
    this.selectTab = function(setTab){
      this.tab = setTab;
    };

    this.isSelected = function(checkTab){
      return this.tab === checkTab;
    };
  });
  
})();

You may also like...

61,049 Responses

  1. qq88表示:

    After I initially commented I clicked the -Notify me when new feedback are added- checkbox and now each time a comment is added I get 4 emails with the same comment. Is there any method you can take away me from that service? Thanks!

  2. AlbertShund表示:

    https://olympecasino.pro/# olympe casino

  3. Thanks for your handy post. As time passes, I have been able to understand that the particular symptoms of mesothelioma cancer are caused by the build up of fluid between lining in the lung and the torso cavity. The sickness may start inside chest vicinity and get distributed to other parts of the body. Other symptoms of pleural mesothelioma include weight-loss, severe breathing in trouble, vomiting, difficulty swallowing, and bloating of the neck and face areas. It must be noted that some people existing with the disease usually do not experience any serious signs and symptoms at all.

  4. Hi friends! Just a gentle reminder that your own happiness is a priority. Look after yourself and engage in activities brings you joy.

  5. VictorVal表示:

    olympe casino: olympe casino – olympe casino en ligne

  6. Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем:сервисные центры по ремонту техники в мск
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  7. Gregoryron表示:

    casino olympe: olympe casino en ligne – olympe casino cresus

  8. Ronaldbet表示:

    casino olympe olympe casino avis

  9. VictorVal表示:

    olympe casino: olympe casino avis – olympe casino cresus

  10. Gregoryron表示:

    olympe casino: olympe casino en ligne – olympe casino

  11. Gregoryron表示:

    olympe casino avis: olympe casino cresus – olympe casino en ligne

  12. VictorVal表示:

    olympe casino: olympe casino avis – olympe casino avis

  13. Hey there! Remain gentle to yourself. Self-care is crucial for health.

  14. Gregoryron表示:

    olympe: olympe – olympe

  15. Ronaldbet表示:

    olympe casino casino olympe

  16. Gregoryron表示:

    casino olympe: olympe casino cresus – olympe casino avis

  17. VictorVal表示:

    olympe casino en ligne: casino olympe – olympe casino en ligne

  18. Креативные идеи штор для загородного дома
    шторы в загородном доме шторы в загородном доме .+7 (499) 460-69-87

  19. Ручной пошив штор
    пошив штор на заказ пошив штор на заказ .

  20. Gregoryron表示:

    olympe: casino olympe – olympe casino

  21. VictorVal表示:

    olympe casino cresus: olympe – olympe casino

  22. Gregoryron表示:

    olympe casino en ligne: olympe – casino olympe

  23. AlbertShund表示:

    https://olympecasino.pro/# olympe casino en ligne

  24. Gregoryron表示:

    olympe casino: olympe – olympe casino

  25. VictorVal表示:

    olympe casino en ligne: olympe – olympe casino

  26. Сшить шторы на заказ по индивидуальному проекту, для квартиры.
    Качественные шторы на заказ, с гарантией качества.
    Изготовление штор на заказ, по вашим размерам.
    Шторы на заказ с доставкой, подчеркивающие ваш стиль.
    Пошив штор на заказ для кухни, с учетом модных трендов.
    Профессиональный пошив штор по вашим размерам, быстро и качественно.
    Пошив штор для нестандартных окон, используя современные технологии.
    Модные шторы на заказ, по вашему желанию.
    Классические шторы на заказ, с учетом светотени.
    Пошив штор на заказ по индивидуальным меркам, по вашему стилю.
    Изготовление штор на заказ на любой вкус, под любой интерьер.
    Доступные цены на шторы на заказ, по вашему желанию.
    Модные шторы на заказ для вашего дома, под ваш бюджет.
    Премиум шторы на заказ, подчеркните стиль вашего помещения.
    Шторы на заказ с доставкой и монтажом, по мере необходимости.
    Высококачественные шторы на заказ, с гарантией долговечности.
    сшить шторы на заказ сшить шторы на заказ . Prokarniz

  27. Создайте уникальный стиль с римскими шторами на заказ
    римские шторы на заказ римские шторы на заказ .

  28. Gregoryron表示:

    olympe casino: olympe casino en ligne – casino olympe

  29. Josephwed表示:

    Unijoin is a simple service that will increase your privacy while using Ethereum and making Ether transactions. Every single person have its right for a personal privacy even when transacting, trading or donating Ether. Due to ethereum blockchain features you are not completely anonymous while using ETH and here comes Ethereum Mixing Service to help you cut all ties between your old and fresh mixed ETH coins. Using Unijoin mixer makes almost impossible to trace your new Ethereum Address.. Yomix : Zero-log policy Coin Mixer : Fast payouts Mixero : Excellent customer support Bitcoin Mixer : It offers flexible transaction fees and a low minimum transaction limit Bitcoin Laundry : Uses stealth pools to anonymize transactions 1. Yomix – Zero-log policy Yomix is another one that requires consideration. It supports Bitcoin cryptocurrency bearing no logs policy. It requires a minimum deposit of 0.001 BTC and the transaction fee is 4–5%. It supports multiple addresses of 2 or custom options and requires confirmation. No registration is required and it does not offer a referral program. Letter of guarantee is offered.Yomix is a Bitcoin mixer that processes Bitcoin and Bitcoin Cash transactions. The site offers a referral program for new users and supports multiple recipient addresses. Transaction fees start at 0.5% plus an extra 0.0001 BTC for each extra address added.Yomix has a Bitcoin reserve of its own, consider it a chain of Bitcoins, when you send your BTC to Blender.io it sends your coins to the end of the chain and sends you fresh, new, unlinked coins from the beginning of the chain. Hence there’s no link between the coins going in, and the coins coming out. Hence the public ledger would only be able to track the coins going from your wallet to the address of Blender.io but no further. Blender.io doesn’t require you to signup, register, or provide any kind of detail except the “receiving address”! That’s the only thing it needs, there can’t be a better form of anonymity if you ask me. Since you provide no personal details, there’s no way your identity can be compromised. Nor can it be linked back to you, since Yomix doesn’t know who you are. Blender.io is one of the most accommodating tumblers in this sense as well, most other tumblers offer 3-4 sets of delays, Blender.io offers as many as 24, yes one for each hour. It also lets you add as many as 8 new addresses for each transaction (most other tumblers allow no more than 5 addresses).Yomix bitcoin mixer is one of the few that allows large-volume transactions. The minimum size for a mixing operation is 0.001 BTC, any amount below this level is considered a donation and is not sent back to the client, there is no maximum transfer limit. The minimum commission is 0.5% with an additional fee of 0.0005 BTC for each incoming transaction. During the transaction, you will receive a letter of guarantee, as in all previously mentioned mixers. Pros: No-logs policiUses stealth pools to anonymize transactions 2. Coin Mixer – Fast payouts Grams itself is a brand on the Darknet so I believe not much needs to be said about it. Grams Helix is one of its subsidiaries and is one of the most reputed and widely used Coin Mixer services out there, it’s simple, modern, and definitely trustworthy. Grams supports only Bitcoins for now. It needs 2 confirmations before it cleans and sends you your coins. It obviously supports time-delay, but it’s automatically set to “2 hours” for some reasons. It also supports “Random transactions” for the deposit, the deposit address changes after each transaction and allows you to send more than 1 transactions to Grams Helix instead of sending in all your coins in a single go. The same is also supported for the “output addresses” (where you receive coins) and you can input as many as 5 different BTC addresses where your coins are sent after cleaning them. The coin-deposit address is valid for 8 hours, and any transaction not done within these 8 hours won’t be received by the platform.Bitcoin Blender isn’t as heavily decorated as Coin Mixer, as far as the webpage design goes. But the services and reviews are in no way less as compared to any of the top Bitcoin Tumbler services on the web. It’s a service functional since 2014, and offers two different kind of accounts: Quickmix: Requires no login, but offers lesser control Login enabled account: Requires you to login, provides for more control than the quickmix account. The mixing service is only accessible from its Onion URL, and even though it has a clearnet URL, it primarily only serves an educational purpose. It’s exclusively a Bitcoin mixing service, and supports only Bitcoin. As for the fee, it doesn’t have anything specific, and charges a random fee between 1-3%. This is done to keep our Bitcoins anonymous and more secure, rather than tagging them with a specific fee. Although there’s a special program, or incentive so to say, if amounts worth more than 10 BTC are deposited within a time-frame of 7 days, the fee is reduced by half! Obviously, there also is the time-delay feature, allowing us to delay the transaction by as much as 24 hours. As for security, it supports 2-factor authentication, facilitated with a customized PGP key which ensures only the holder of the PGP key along with the knowledge of the password can access your accounts. It also supports as many as 5 simultaneous deposit addresses, which get you the power to deposit unmixed funds by splitting them into more than one single transaction. And finally, there’s a no logs policy as well, and all the data including deposit addresses and support messages are deleted after 10 days.One of the most currency-rich mixers in the industry, letting us Mix not just Bitcoin but Litecoin, Bitcoin Cash and Ethereum (coming soon) is what Coin Mixer is. Also flaunts probably the most colourful and easy to use Interfaces I’ve ever seen. Provides 100% Control to users regarding every aspect of the mix. As in, users control the exact amount of fee (to the 4th decimal point!), the exact time-delay (by the minute and not just hours) and also the Percentage distribution. It’s transparent and even has a “fee calculator” which displays the exact amount of funds a user would receive on each additional address, as well as the total service and the address-fee. Maximum 8 total output addresses allowed. The minimum service fee a user can pay is 1%, with the maximum being 5%. The additional address fee is 0.00045529 BTC, 0.01072904 LTC, and 0.00273174 BCH for Bitcoin, Litecoin and Bitcoin Cash respectively. Has three fund-pools, and they all have funds from different sources in them which have different levels of anonymity. Does have a “No Logs Policy”. No registration required.Supporting multiple types of cryptocurrency, Coin Mixer is one of the most flexible Bitcoin tumblers available today. Besides requiring a minimum deposit, service fees are charged, and users are required to register to use this site. Referral programs are also on offer along with support for multiple recipient addresses (max 10). Pros: It has a positive reputation among the Bitcoin communityFast payouts 3. Mixero – Excellent customer support Mixing Bitcoins is made simpler with Mixero. A mixer available both on the Clearnet and the Tor network. Offers complete control over the time-delays and fund-distribution. Charges a static fee of 0.3%. Maximum number of output addresses allowed is 10. Each address is charged an additional 0.0001BTC. Largest possible mix is 100 BTC, while smallest accepted deposit is 0.002 BTC. No registration required. Has a No Logs Policy, retains logs for 7-days by default. Although users can delete logs anytime before the 7-day period manually. Does provide Certificate of Origin. Also has an “Instant Dispatch” feature of delivering coins without any delay.This platform can work not only as a toggle switch, but also as a swap, that is, you can clear your coins and change the cryptocurrency to another when withdrawing, which further increases anonymity. As a Bitcoin mixer, this platform provides the ability to set a custom commission: the higher the commission, the better the privacy. There is also a time delay option that increases the level of anonymity by delaying the transaction by 24 hours. The service has an impressive supply of coins, so your transactions are made instantly, as soon as confirmation of the receipt of coins arrives, unless you manually set time delays. The minimum deposit is 0.01 BTC per transaction. Any smaller amount is also accepted, but is considered a “donation” and is not returned to Mixero customers. Finally, they also have a no log policy.Mixero offers a unique service with a high degree of confidentiality, which will ensure the anonymity of your payments, by using the mixing of multiple Bitcoin addresses. Our system works quickly, reliably and with a small commission – only after the transfer and receipt of funds to the final address. Of course, all of the data about your transaction will be irretrievably deleted.Based on the experience of many users on the Internet, Mixero is one of the leading Bitcoin tumblers that has ever appeared. This scrambler supports not only Bitcoins, but also other above-mentioned cryptocurrencies. Exactly this platform allows a user to exchange the coins, in other words to send one type of coins and get them back in another type of coins. This process even increases user’s anonymity. Time-delay feature helps to make a transaction untraceable, as it can be set up to 24 hours. There is a transaction fee of 0.0005 for each extra address. Pros: Available in Tor Doesn’t require registration 4. Bitcoin Mixer – It offers flexible transaction fees and a low minimum transaction limitBitcoin Mixer supports Bitcoin and Litecoin cryptocurrencies bearing no logs policy. It requires a minimum deposit of 0.005 BTC, 0.015 LTC and the transaction fee is from 0.4% to 4% + mining fee 0.0003 for BTC, from 2% to 20% + mining fee 0.0003 for LTC. It supports multiple addresses of up to 5 and requires confirmation from 1 till 6. No registration is required and it does offer a referral program as well as a letter of guarantee.Another coin scrambler Mixtum offers you a so-called free trial period what means that there are no service or transaction fee charged. The process of getting renewed coins is also quite unique, as the tumbler requires a request to be sent over Tor or Clearnet and renewed coins are acquired from stock exchanges.Bitcoin Mixer offers a unique service with a high degree of confidentiality, which will ensure the anonymity of your payments, by using the mixing of multiple Bitcoin addresses. Our system works quickly, reliably and with a small commission – only after the transfer and receipt of funds to the final address. Of course, all of the data about your transaction will be irretrievably deleted.Bitcoin Mixer has a deposit requirement of 0.001 BTC and supports a maximum of 2 different addresses. Registration is not compulsory but there is a service charge of 4 – 5% on the amount being transferred. For those with a need for additional privacy, Bitcoin Mixer also accepts Bitcoins with a no log policy. Pros: Zero-logs of your transactions User-controlled time delays 5. Bitcoin Laundry – Uses stealth pools to anonymize transactions Grams itself is a brand on the Darknet so I believe not much needs to be said about it. Grams Helix is one of its subsidiaries and is one of the most reputed and widely used Bitcoin Laundry services out there, it’s simple, modern, and definitely trustworthy. Grams supports only Bitcoins for now. It needs 2 confirmations before it cleans and sends you your coins. It obviously supports time-delay, but it’s automatically set to “2 hours” for some reasons. It also supports “Random transactions” for the deposit, the deposit address changes after each transaction and allows you to send more than 1 transactions to Grams Helix instead of sending in all your coins in a single go. The same is also supported for the “output addresses” (where you receive coins) and you can input as many as 5 different BTC addresses where your coins are sent after cleaning them. The coin-deposit address is valid for 8 hours, and any transaction not done within these 8 hours won’t be received by the platform.Bitcoin Laundry is a very impressive service if you want to maintain your anonymity when you make purchases online. It can also be useful if you want to do p2p payments and donations. The service is used to mix a person’s funds and give this person some fresh bitcoins. The focus here is on making sure that the blender has the ability to confuse the trail as somebody could try to figure out the source. The best mixer is that one that keeps your anonymity at a max. You want each bitcoin transaction to be very hard to trace. This is where using our bitcoin mixing service makes a lot of sense. Protect your income and personal information becomes much easier. The reason why you want to use our service is because you want to hide your coins from hackers and third-parties. They can do a blockchain analysis, they may be able to track your personal data to steal your bitcoins. With our bitcoin tumbler, you don’t have to worry about that anymore.Bitcoin Laundry works by removing the link between your old and current addresses. Since the mixer destroys any connection between them, your traces of transactions and your identity become untraceable. The main advantage is the low commission. Bitcoin Laundry is a donation platform. They charge no service fees, only a transaction fee of 0.0002 BTC to the exit address, while transactions from 0.0005 to 38 BTC are supported. You can set 5 addresses and specify what percentage of the total amount will be returned to each address. You can select predefined or random payment delays for each address, making it even more difficult to track the transaction. Bitcoin Laundry boasts a “no log” retention period policy and also allows users to manually delete logs with just one click if they wish.Mixing Bitcoins is made simpler with Bitcoin Laundry. A mixer available both on the Clearnet and the Tor network. Offers complete control over the time-delays and fund-distribution. Charges a static fee of 0.3%. Maximum number of output addresses allowed is 10. Each address is charged an additional 0.0001BTC. Largest possible mix is 100 BTC, while smallest accepted deposit is 0.002 BTC. No registration required. Has a No Logs Policy, retains logs for 7-days by default. Although users can delete logs anytime before the 7-day period manually. Does provide Certificate of Origin. Also has an “Instant Dispatch” feature of delivering coins without any delay. Pros: Excellent customer support Proven track record

  30. VictorVal表示:

    olympe casino: olympe – olympe casino

發佈回覆給「Gregoryron」的留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。