Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 5b8a290

Browse files
committed
make wording about stateful filters less strong
1 parent 483a2e4 commit 5b8a290

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/content/guide/filter.ngdoc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ E.g. the markup `{{ 1234 | number:2 }}` formats the number 1234 with 2 decimal p
3535

3636
In templates, filters are only executed when their inputs have changed. This is more performant than executing
3737
a filter on each {@link ng.$rootScope.Scope#$digest `$digest`} as is the case with {@link guide/expression expressions}.
38-
However, this is only true for filters that take [primitive values](https://developer.mozilla.org/docs/Glossary/Primitive)
38+
39+
There are two exceptions to this rule:
40+
41+
1. In general, this applies only to filters that take [primitive values](https://developer.mozilla.org/docs/Glossary/Primitive)
3942
as inputs. Filters that receive [Objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Objects)
40-
as input are executed on each `$digest`, as it would be too costly to track if they have changed.
43+
as input are executed on each `$digest`, as it would be too costly to track if the inputs have changed.
44+
45+
2. Filters that are marked as `$stateful` are also executed on each $digest.
46+
See {@link guide/filter#stateful-filters Stateful filters} for more information. Note that no Angular
47+
core filters are $stateful.
4148

42-
This means custom filters should only rely on their inputs and not on external state (e.g. other Angular services).
43-
See {@link guide/filter#creating-custom-filters Creating custom filters} below for more information.
4449

4550
## Using filters in controllers, services, and directives
4651

@@ -103,8 +108,9 @@ as the first argument. Any filter arguments are passed in as additional argument
103108
function.
104109

105110
The filter function should be a [pure function](http://en.wikipedia.org/wiki/Pure_function), which
106-
means that it should be stateless and idempotent. Angular relies on these properties and executes
107-
the filter only when the inputs to the function change.
111+
means that it should be stateless and idempotent, and not rely for example on other Angular services.
112+
Angular relies on this contract and will by default execute a filter only when the inputs to the function change.
113+
{@link guide/filter#stateful-filters Stateful filters} are possible, but less performant.
108114

109115
<div class="alert alert-warning">
110116
**Note:** Filter names must be valid angular {@link expression} identifiers, such as `uppercase` or `orderBy`.

0 commit comments

Comments
 (0)