官术网_书友最值得收藏!

Pipes

In business applications, we often need to have different visual representations of the same piece of data. For example, if we have the number 100,000 and we want to format it as currency, most likely we won't want to display it as plain data; more likely, we'll want something like $100,000.

The responsibility for formatting data in AngularJS was assigned to filters. Another example for a data formatting requirement is when we use collections of items. For instance, if we have a list of items, we may want to filter it based on a predicate (a Boolean function); in a list of numbers, we may want to display only the prime numbers. AngularJS has a filter called filter, which allows us to do this. However, the duplication of the names often leads to confusion. This is one of the reasons the core team renamed the filter component to pipe. Also, the word filter predisposes us to think that filters are only responsible for filtering data, when they have the much more generic responsibility of formatting data.

The motivation behind the new name is the syntax used for pipes and filters:

{{expression | decimal | currency}} 

In the preceding example, we apply the decimal and currency pipes to the value returned by expression. The entire expression between the curly braces looks like the Unix pipe syntax.

主站蜘蛛池模板: 涟水县| 离岛区| 正宁县| 德化县| 嘉义县| 自治县| 商河县| 商洛市| 永年县| 长沙县| 内丘县| 化州市| 宜君县| 永定县| 佛冈县| 陕西省| 林芝县| 玉龙| 元江| 吴旗县| 巩留县| 教育| 维西| 张家界市| 全椒县| 阿拉善盟| 永泰县| 玛多县| 镇雄县| 西贡区| 德钦县| 郎溪县| 阜城县| 滦平县| 潮州市| 多伦县| 巫山县| 岱山县| 平利县| 灌云县| 扶绥县|