Skip to content

docs: Notes on why and when to use NgZone #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/ng-ui-widgets-category/bottom-navigation/events/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
- `oldIndex` - Provides the old selected index.
- `newIndwex` - Provides the new selected index.

<snippet id='bottom-navigation-events-ng'/>
<snippet id='bottom-navigation-events-ng'/>

> **Note:** Any UI event declared throught the HTML markup will be automatically wrapped in the Angular zone. This is not the case when the events are declared thorugh the code behind (e.g., when using `on`) so in such cases we need to manually wrap any event that will be called from a native code:
```TypeScript
constructor(private _zone: NgZone) { }

// .. more code follows here

bottomNavigation.on(BottomNavigation.selectedIndexChangedEvent, (args: SelectedIndexChangedEventData) => {
// manually wrap in the NgZone when using the event via code-behind
this._zone.run(() => {
this.selectedIndex = args.newIndex;
});
});
```
15 changes: 14 additions & 1 deletion app/ng-ui-widgets-category/tabs/events/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@
- `oldIndex` - Provides the old selected index.
- `newIndwex` - Provides the new selected index.

<snippet id='tabs-events-ng'/>
<snippet id='tabs-events-ng'/>

> **Note:** Any UI event declared throught the HTML markup will be automatically wrapped in the Angular zone. This is not the case when the events are declared thorugh the code behind (e.g., when using `on`) so in such cases we need to manually wrap any event that will be called from a native code:
```TypeScript
constructor(private _zone: NgZone) { }

// .. more code follows here

tabs.on(Tabs.selectedIndexChangedEvent, (args: SelectedIndexChangedEventData) => {
// manually wrapping in the NgZone when using the event via code-behind (otherwise this.selectedIndex won't be updated in the UI)
this._zone.run(() => {
this.selectedIndex = args.newIndex;
});
});