Skip to content

Commit e783b48

Browse files
authored
Merge pull request #396 from NativeScript/niliev/ngzone
docs: Notes on why and when to use NgZone
2 parents 5dc3e79 + dbd1964 commit e783b48

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

app/ng-ui-widgets-category/bottom-navigation/events/article.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@
22
- `oldIndex` - Provides the old selected index.
33
- `newIndwex` - Provides the new selected index.
44

5-
<snippet id='bottom-navigation-events-ng'/>
5+
<snippet id='bottom-navigation-events-ng'/>
6+
7+
> **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:
8+
```TypeScript
9+
constructor(private _zone: NgZone) { }
10+
11+
// .. more code follows here
12+
13+
bottomNavigation.on(BottomNavigation.selectedIndexChangedEvent, (args: SelectedIndexChangedEventData) => {
14+
// manually wrap in the NgZone when using the event via code-behind
15+
this._zone.run(() => {
16+
this.selectedIndex = args.newIndex;
17+
});
18+
});
19+
```

app/ng-ui-widgets-category/tabs/events/article.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,17 @@
22
- `oldIndex` - Provides the old selected index.
33
- `newIndwex` - Provides the new selected index.
44

5-
<snippet id='tabs-events-ng'/>
5+
<snippet id='tabs-events-ng'/>
6+
7+
> **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:
8+
```TypeScript
9+
constructor(private _zone: NgZone) { }
10+
11+
// .. more code follows here
12+
13+
tabs.on(Tabs.selectedIndexChangedEvent, (args: SelectedIndexChangedEventData) => {
14+
// manually wrapping in the NgZone when using the event via code-behind (otherwise this.selectedIndex won't be updated in the UI)
15+
this._zone.run(() => {
16+
this.selectedIndex = args.newIndex;
17+
});
18+
});

0 commit comments

Comments
 (0)