From 215db7fbe6c91c43383a784b8d74c8063ce5c340 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 24 Jan 2022 10:25:12 +0100 Subject: [PATCH] fix(core): error if NgZone.isInAngularZone is called with a noop zone (#44800) When the user opts into the noop `NgZone`, they usually still interact with the static methods on the non-noop class. This change adds a check to handle the case where zone.js hasn't been loaded. Fixes #44784. PR Close #44800 --- packages/core/src/zone/ng_zone.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/zone/ng_zone.ts b/packages/core/src/zone/ng_zone.ts index 74d1748116e..f1b43120d4f 100644 --- a/packages/core/src/zone/ng_zone.ts +++ b/packages/core/src/zone/ng_zone.ts @@ -153,7 +153,8 @@ export class NgZone { } static isInAngularZone(): boolean { - return Zone.current.get('isAngularZone') === true; + // Zone needs to be checked, because this method might be called even when NoopNgZone is used. + return typeof Zone !== 'undefined' && Zone.current.get('isAngularZone') === true; } static assertInAngularZone(): void {