javascript 管道在这个 AngularJS 表达式中做了什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19371641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does the pipe do in this AngularJS expression
提问by Luke101
<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>
The |
in the above code - what does it do?
在|
上面的代码-它有什么作用?
回答by TyndieRock
The pipe symbol (|) is used for applying filters in AngularJS. A filter is a function that is invoked for handling model transformations. Its basically just a global function that doesn't require registration of functions on a scope, and offers more convenient syntax to regular function calls. The currency filter automatically formats a number in the current currency locale of the user.
管道符号 (|) 用于在 AngularJS 中应用过滤器。过滤器是一个被调用以处理模型转换的函数。它基本上只是一个全局函数,不需要在作用域上注册函数,并为常规函数调用提供更方便的语法。货币过滤器自动在用户的当前货币区域设置中格式化数字。
[Video content unfortunately now behind paywall] Check out this video for an example http://egghead.io/lessons/angularjs-built-in-filters
[不幸的是,视频内容现在在付费专区后面] 查看此视频以获取示例 http://egghead.io/lessons/angularjs-built-in-filters