1
1
import {
2
- afterNextRender ,
3
2
DestroyRef ,
4
3
Directive ,
4
+ effect ,
5
5
EmbeddedViewRef ,
6
6
inject ,
7
7
input ,
8
- NgZone ,
9
8
TemplateRef ,
10
9
untracked ,
11
10
ViewContainerRef ,
12
11
} from '@angular/core' ;
13
- import { injectAutoEffect } from 'ngxtension/auto-effect' ;
14
12
import { SPECIAL_INTERNAL_ADD_COMMENT } from '../renderer/constants' ;
15
13
16
14
@Directive ( { selector : 'ng-template[args]' , standalone : true } )
17
15
export class NgtArgs {
18
16
args = input . required < any [ ] | null > ( ) ;
19
17
20
18
private vcr = inject ( ViewContainerRef ) ;
21
- private zone = inject ( NgZone ) ;
22
19
private template = inject ( TemplateRef ) ;
23
- private autoEffect = injectAutoEffect ( ) ;
24
20
25
21
protected injected = false ;
26
22
protected injectedArgs : any [ ] | null = null ;
@@ -33,15 +29,13 @@ export class NgtArgs {
33
29
delete commentNode [ SPECIAL_INTERNAL_ADD_COMMENT ] ;
34
30
}
35
31
36
- afterNextRender ( ( ) => {
37
- this . autoEffect ( ( ) => {
38
- const value = this . args ( ) ;
39
- if ( value == null || ! Array . isArray ( value ) || ( value . length === 1 && value [ 0 ] === null ) ) return ;
40
- this . injected = false ;
41
- this . injectedArgs = value ;
42
- untracked ( ( ) => {
43
- this . createView ( ) ;
44
- } ) ;
32
+ effect ( ( ) => {
33
+ const value = this . args ( ) ;
34
+ if ( value == null || ! Array . isArray ( value ) || ( value . length === 1 && value [ 0 ] === null ) ) return ;
35
+ this . injected = false ;
36
+ this . injectedArgs = value ;
37
+ untracked ( ( ) => {
38
+ this . createView ( ) ;
45
39
} ) ;
46
40
} ) ;
47
41
@@ -63,12 +57,8 @@ export class NgtArgs {
63
57
}
64
58
65
59
private createView ( ) {
66
- this . zone . runOutsideAngular ( ( ) => {
67
- if ( this . view && ! this . view . destroyed ) {
68
- this . view . destroy ( ) ;
69
- }
70
- this . view = this . vcr . createEmbeddedView ( this . template ) ;
71
- this . view . detectChanges ( ) ;
72
- } ) ;
60
+ if ( this . view && ! this . view . destroyed ) this . view . destroy ( ) ;
61
+ this . view = this . vcr . createEmbeddedView ( this . template ) ;
62
+ this . view . detectChanges ( ) ;
73
63
}
74
64
}
0 commit comments