router subscription executed inside of Angular zone even when wrapped in runOutsideAngular()
See original GitHub issueI’m submitting a …
[x] bug report
[ ] feature request
[ ] support request
Current behavior It seems that runOutsideAngular() is not working consistently in combination with routing.
If I surround a subscription to ActiveRoute.params with ngZone.runOutsideAngular() within a component, it will run outside of the Angular zone for the initial navigation, but return to the zone for subsequent router navigations.
Expected behavior
If I wrap any subscription in ngZone.runOutsideAngular(), I would expect the code to run outside of zone consistently.
Minimal reproduction of the problem with instructions Minimal working example: http://plnkr.co/edit/bg3nuimPGNppsF5wX20h?p=preview
There is one default redirection in the routes to ‘/foo’ and one manually in the SubComponent to ‘/foo2’.
The console output shows the strange behaviour:
param: foo, run outside of zone: true
param: foo2, run outside of zone: false // <-- I would expect this to be true!
The relevant code is in sub.component.ts:
@Component({
template: 'RouteParam: {{ activeRoute }}'
})
export class SubComponent {
public activeRoute: string;
constructor(private route: ActivatedRoute, private ngZone: NgZone, private router: Router) {
this.ngZone.runOutsideAngular(() => {
route.params
.map(params => params['routeParam'])
.do(param => console.log('param: ' + param + ', run outside of zone: ' + !NgZone.isInAngularZone()))
.subscribe(param => this.activeRoute = param);
this.router.navigate(['foo2']);
});
}
}
What is the motivation / use case for changing the behavior? I want to combine the params with HTTP polling, so I need the subscription to run outside of the ngZone or protractor will time out. (see http://stackoverflow.com/questions/36358405/how-to-implement-intervals-polling-in-angular2-to-work-with-protractor)
Please tell us about your environment: Windows 10, Angular CLI 1.0.0-rc.1
-
Angular version: reproduced with 2.4.0 and 4.0.2
-
Browser: all
-
Language: TypeScript 2.0.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)

Top Related StackOverflow Question
@jasonaden, , this one has been closed https://github.com/ReactiveX/rxjs/pull/2266. @magnattic, and now
zone.jshas a new patch forrxjs, you can try toin
polyfillafterimport zoneThis issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.