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';
17
17
export * from './lib/utils/instance' ;
18
18
export * from './lib/utils/is' ;
19
19
export * from './lib/utils/make' ;
20
+ export * from './lib/utils/safe-detect-changes' ;
20
21
export * from './lib/utils/update' ;
Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ import {
11
11
switchMap ,
12
12
takeUntil ,
13
13
} from 'rxjs' ;
14
- import type { NgtAnyRecord , NgtInstanceNode } from '../types' ;
14
+ import type { NgtInstanceNode } from '../types' ;
15
15
import { getLocalState } from '../utils/instance' ;
16
16
import { is } from '../utils/is' ;
17
+ import { safeDetectChanges } from '../utils/safe-detect-changes' ;
17
18
import { injectNgtDestroy } from './destroy' ;
18
19
19
20
type Subscribe < T > = ( callback : ( current : T , previous : T | null ) => void ) => Subscription ;
@@ -102,9 +103,7 @@ export function injectNgtRef<T>(initialValue: NgtInjectedRef<T> | (T | null) = n
102
103
// during creation phase, 'context' on ViewRef will be null
103
104
// we check the "context" to avoid running detectChanges during this phase.
104
105
// because there's nothing to check
105
- if ( ( cd as NgtAnyRecord ) [ 'context' ] ) {
106
- cd . detectChanges ( ) ;
107
- }
106
+ safeDetectChanges ( cd ) ;
108
107
}
109
108
}
110
109
} ,
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