Skip to content

Commit

Permalink
docs: add section on binding to passive events (#42292)
Browse files Browse the repository at this point in the history
fixes #41622

PR Close #42292
  • Loading branch information
David Shevitz authored and umairhm committed May 28, 2021
1 parent 3ddc92b commit 66b447a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions aio/content/guide/event-binding.md
Expand Up @@ -24,6 +24,26 @@ The event binding listens for the button's click events and calls the component'
<img src='generated/images/guide/template-syntax/syntax-diagram.svg' alt="Syntax diagram">
</div>

## Binding to passive events

Angular also supports passive event listeners. For example, you can use the following steps to make a scroll event passive.

1. Create a file `zone-flags.ts` under `src` directory.
2. Add the following line into this file.

```
(window as any)['__zone_symbol__PASSIVE_EVENTS'] = ['scroll'];
```

3. In the `src/polyfills.ts` file, before importing zone.js, import the newly created `zone-flags`.

```
import './zone-flags';
import 'zone.js'; // Included with Angular CLI.
```

After those steps, if you add event listeners for the `scroll` event, the listeners will be `passive`.

## Custom events with `EventEmitter`

[Directives](guide/built-in-directives) typically raise custom events with an Angular [EventEmitter](api/core/EventEmitter) as follows.
Expand Down

0 comments on commit 66b447a

Please sign in to comment.