File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,5 @@ export { createAttachFunction } from './lib/utils/attach';
1717export * from './lib/utils/instance' ;
1818export * from './lib/utils/is' ;
1919export * from './lib/utils/make' ;
20+ export * from './lib/utils/safe-detect-changes' ;
2021export * from './lib/utils/update' ;
Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ import {
1111 switchMap ,
1212 takeUntil ,
1313} from 'rxjs' ;
14- import type { NgtAnyRecord , NgtInstanceNode } from '../types' ;
14+ import type { NgtInstanceNode } from '../types' ;
1515import { getLocalState } from '../utils/instance' ;
1616import { is } from '../utils/is' ;
17+ import { safeDetectChanges } from '../utils/safe-detect-changes' ;
1718import { injectNgtDestroy } from './destroy' ;
1819
1920type Subscribe < T > = ( callback : ( current : T , previous : T | null ) => void ) => Subscription ;
@@ -102,9 +103,7 @@ export function injectNgtRef<T>(initialValue: NgtInjectedRef<T> | (T | null) = n
102103 // during creation phase, 'context' on ViewRef will be null
103104 // we check the "context" to avoid running detectChanges during this phase.
104105 // because there's nothing to check
105- if ( ( cd as NgtAnyRecord ) [ 'context' ] ) {
106- cd . detectChanges ( ) ;
107- }
106+ safeDetectChanges ( cd ) ;
108107 }
109108 }
110109 } ,
Original file line number Diff line number Diff line change 1+ import { ChangeDetectorRef } from '@angular/core' ;
2+ import { NgtAnyRecord } from '../types' ;
3+
4+ export function safeDetectChanges ( cdr : ChangeDetectorRef ) {
5+ try {
6+ if ( ( cdr as NgtAnyRecord ) [ 'context' ] ) {
7+ cdr . detectChanges ( ) ;
8+ }
9+ } catch ( e ) {
10+ cdr . markForCheck ( ) ;
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments