5
5
ElementRef ,
6
6
HostBinding ,
7
7
Inject ,
8
- Input , OnChanges ,
8
+ Input ,
9
+ OnChanges ,
9
10
OnDestroy ,
10
11
OnInit ,
11
12
Renderer2 ,
@@ -39,10 +40,11 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
39
40
*/
40
41
@Input ( 'cTooltipOptions' )
41
42
set popperOptions ( value : Partial < Options > ) {
42
- this . _popperOptions = { ...this . _popperOptions , placement : this . placement , ...value } ;
43
+ this . _popperOptions = { ...this . _popperOptions , placement : this . placement , ...value } ;
43
44
} ;
45
+
44
46
get popperOptions ( ) : Partial < Options > {
45
- return { placement : this . placement , ...this . _popperOptions } ;
47
+ return { placement : this . placement , ...this . _popperOptions } ;
46
48
}
47
49
48
50
/**
@@ -61,12 +63,12 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
61
63
@Input ( 'cTooltipVisible' )
62
64
set visible ( value : boolean ) {
63
65
this . _visible = value ;
64
- value ? this . addTooltipElement ( ) : this . removeTooltipElement ( ) ;
65
- this . tooltipRef ?. changeDetectorRef . markForCheck ( ) ;
66
66
}
67
+
67
68
get visible ( ) {
68
69
return this . _visible ;
69
70
}
71
+
70
72
private _visible = false ;
71
73
72
74
@HostBinding ( 'attr.aria-describedby' ) get ariaDescribedBy ( ) : string | null {
@@ -83,10 +85,10 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
83
85
{
84
86
name : 'offset' ,
85
87
options : {
86
- offset : [ 0 , 0 ] ,
87
- } ,
88
- } ,
89
- ] ,
88
+ offset : [ 0 , 0 ]
89
+ }
90
+ }
91
+ ]
90
92
} ;
91
93
92
94
constructor (
@@ -110,7 +112,6 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
110
112
}
111
113
112
114
ngOnInit ( ) : void {
113
- // this.createTooltipElement();
114
115
this . setListeners ( ) ;
115
116
}
116
117
@@ -120,15 +121,18 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
120
121
trigger : this . trigger ,
121
122
callbackToggle : ( ) => {
122
123
this . visible = ! this . visible ;
124
+ this . visible ? this . addTooltipElement ( ) : this . removeTooltipElement ( ) ;
123
125
} ,
124
126
callbackOff : ( ) => {
125
127
this . visible = false ;
128
+ this . removeTooltipElement ( ) ;
126
129
} ,
127
130
callbackOn : ( ) => {
128
131
this . visible = true ;
132
+ this . addTooltipElement ( ) ;
129
133
}
130
- }
131
- this . listenersService . setListeners ( config )
134
+ } ;
135
+ this . listenersService . setListeners ( config ) ;
132
136
}
133
137
134
138
private clearListeners ( ) : void {
@@ -146,8 +150,11 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
146
150
147
151
private createTooltipElement ( ) : void {
148
152
if ( ! this . tooltipRef ) {
149
- const tooltipComponent = this . componentFactoryResolver . resolveComponentFactory ( TooltipComponent ) ;
150
- this . tooltipRef = this . viewContainerRef . createComponent ( tooltipComponent ) ;
153
+ const tooltipComponent =
154
+ this . componentFactoryResolver . resolveComponentFactory ( TooltipComponent ) ;
155
+ this . tooltipRef = tooltipComponent . create ( this . viewContainerRef . injector ) ;
156
+ // this.tooltipRef = this.viewContainerRef.createComponent<TooltipComponent>(TooltipComponent);
157
+ // this.viewContainerRef.detach();
151
158
}
152
159
}
153
160
@@ -167,34 +174,34 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
167
174
}
168
175
this . tooltipRef . instance . content = this . content ;
169
176
this . tooltip = this . tooltipRef . location . nativeElement ;
177
+ this . renderer . addClass ( this . tooltip , 'fade' ) ;
170
178
171
179
setTimeout ( ( ) => {
172
180
this . popperInstance = createPopper (
173
181
this . hostElement . nativeElement ,
174
182
this . tooltip ,
175
183
{ ...this . popperOptions }
176
184
) ;
185
+ this . viewContainerRef . insert ( this . tooltipRef . hostView ) ;
177
186
setTimeout ( ( ) => {
178
187
this . tooltipId = this . getUID ( 'tooltip' ) ;
179
188
this . tooltipRef . instance . id = this . tooltipId ;
180
189
this . tooltipRef . instance . visible = this . visible ;
181
190
this . renderer . appendChild ( this . document . body , this . tooltip ) ;
182
191
this . popperInstance . forceUpdate ( ) ;
183
- this . tooltipRef . changeDetectorRef . markForCheck ( ) ;
184
- // this.tooltipRef.changeDetectorRef.detectChanges();
192
+ // this.tooltipRef.changeDetectorRef.markForCheck();
185
193
} , 100 ) ;
186
- } )
194
+ } ) ;
187
195
}
188
196
189
197
private removeTooltipElement ( ) : void {
190
198
if ( ! this . tooltipRef ) {
191
- return
199
+ return ;
192
200
}
193
201
this . tooltipRef . instance . visible = this . visible ;
202
+ this . tooltipRef . instance . id = undefined ;
194
203
setTimeout ( ( ) => {
195
- // this.tooltipRef.changeDetectorRef.detectChanges();
196
- this . tooltipRef . instance . id = undefined ;
197
- this . renderer . removeChild ( this . document . body , this . tooltip ) ;
204
+ this . viewContainerRef . detach ( ) ;
198
205
this . popperInstance ?. destroy ( ) ;
199
206
this . tooltipId = '' ;
200
207
} , 300 ) ;
0 commit comments