Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output{{
}}
|
{{ filter_expression | filter : expression : comparator : anyPropertyKey}}
$filter('filter')(array, expression, comparator, anyPropertyKey)
Input
Output
In the example above, product
is the object, title
is its attribute,uppercase
Some filters require a parameter to be passed.
Input
Output
Multiple filters can be used on one output. They are applied from left to right.
Input
Output
Filters format the value of an expression for display to the user. They can be used in view templates, controllers or services. AngularJS comes with a collection of built-in filters, but it is easy to define your own as well.
The underlying API is$filterProvider
URL filters output links to assets on StoreHippo Content Delivery Network (CDN). They are also used to create links for images.
Returns the URL of a file in the "assets" folder of a theme.
Input
Output
Returns the URL of a global asset. Global assets are kept in a directory on StoreHippo servers. Input
Output
Returns the URL of an image. Accepts image size parameter. You canimage filter
image
src
image
If you don't include
Input
{{ product.image | image: '240x240' }}
{{ variant.image | image: '640x640' }}
{{ record.image | image: '1024x1024' }}
{{ product.image | image }}
Output
Input
Output
http://cdn.storehippo.com/s/55f01e8806ed25a71f1d28fd/originals/ms.products/58d788cc969dbca336281d5e/images/58d788cc969dbca336281d5f/58d788ccd0ed51d744043d64/webp/58d788ccd0ed51d744043d64.jpeg
50x50 (output : cropped image)
60x60
100x100 (output : cropped image)
120x120
240x240
640x640
1024x1024
2048x2048 (available only for slider images)
String filters are used to manipulate outputs and variables of the string type.
Capitalizes the first word in a string
Input
Output
Remove the underscore in a string
Input
Output
Truncates a string down to the number of characters passed as the first parameter. An ellipsis (...) is appended to the truncated string and is included in the character count.
Input
{{ "The cat came back the very next day" | truncate: 13 }}
Output
The cat ca...
Array filters change the output of arrays.
Returns the subset of the items in an array.
Input
var my_array = ['apples', 'oranges', 'peaches', 'plums']
{{ my_array | chunk:'2' }}
Output
['plums', 'peaches']
General filters serve many different purposes including formatting, converting, and applying translations.
msCurrency filters format prices based on the Currency Settings found in General Settings.
Input
Output
Input
Output
Writing your own filter is very easy: just register a new filter factory function with your module. Internally, this usesfilterProvider