This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -644,7 +644,21 @@ const Zone: ZoneType = (function(global: any) {
644
644
}
645
645
mark ( 'Zone' ) ;
646
646
if ( global [ 'Zone' ] ) {
647
- throw new Error ( 'Zone already loaded.' ) ;
647
+ // if global['Zone'] already exists (maybe zone.js was already loaded or
648
+ // some other lib also registered a global object named Zone), we may need
649
+ // to throw an error, but sometimes user may not want this error.
650
+ // For example,
651
+ // we have two web pages, page1 includes zone.js, page2 doesn't.
652
+ // and the 1st time user load page1 and page2, everything work fine,
653
+ // but when user load page2 again, error occurs because global['Zone'] already exists.
654
+ // so we add a flag to let user choose whether to throw this error or not.
655
+ // By default, if existing Zone is from zone.js, we will not throw the error.
656
+ if ( global [ ( '__zone_symbol__forceDuplicateZoneCheck' ) ] === true ||
657
+ typeof global [ 'Zone' ] . __symbol__ !== 'function' ) {
658
+ throw new Error ( 'Zone already loaded.' ) ;
659
+ } else {
660
+ return global [ 'Zone' ] ;
661
+ }
648
662
}
649
663
650
664
class Zone implements AmbientZone {
You can’t perform that action at this time.
0 commit comments