2013-10-15 29 views
10
<div ng-controller="CartController"> 
    <div ng-repeat="item in items"> 
      <span>{{item.title}}</span> 
      <input ng-model="item.quantity"> 
      <span>{{item.price | currency}}</span> 
      <span>{{item.price * item.quantity | currency}}</span> 
    </div> 
    <div>Total: {{totalCart() | currency}}</div> 
    <div>Discount: {{bill.discount | currency}}</div> 
    <div>Subtotal: {{subtotal() | currency}}</div> 
</div> 

上述代碼中的| - 它有什麼作用?管道在這個AngularJS表達式中做什麼

+5

看一看[角過濾器](http://code.angularjs.org/1.1.5/docs/導向/ dev_guide.templates.filters)。 – dmahapatro

回答

21

管道符號(|)用於在AngularJS中應用過濾器。過濾器是爲處理模型轉換而調用的函數。它基本上只是一個全局函數,不需要在範圍上註冊函數,並且可以爲常規函數調用提供更方便的語法。貨幣過濾器會自動格式化用戶當前貨幣區域設置中的一個數字。

[視頻可惜現在落後付費牆內容] 看看這個視頻爲例 http://egghead.io/lessons/angularjs-built-in-filters

+2

我看了視頻..我認爲過濾器只能與ng-repeat一起使用。這不斷提醒我,angularjs是一個強大的軟件。 – Luke101

+0

這是一個付費視頻! –

+0

嗯,這太糟糕了,這是一個免費的視頻最初 – TyndieRock

相關問題