@@ -4,10 +4,12 @@ import {
4
4
ComponentRef ,
5
5
DestroyRef ,
6
6
Directive ,
7
+ effect ,
7
8
ElementRef ,
8
9
HostBinding ,
9
10
inject ,
10
11
Inject ,
12
+ input ,
11
13
Input ,
12
14
OnChanges ,
13
15
OnDestroy ,
@@ -39,7 +41,7 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit, AfterView
39
41
* Content of tooltip
40
42
* @type {string | TemplateRef }
41
43
*/
42
- @ Input ( 'cTooltip' ) content : string | TemplateRef < any > = '' ;
44
+ readonly content = input < string | TemplateRef < any > > ( '' , { alias : 'cTooltip' } ) ;
43
45
44
46
/**
45
47
* Optional popper Options object, takes precedence over cPopoverPlacement prop
@@ -110,6 +112,11 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit, AfterView
110
112
private intersectionService : IntersectionService
111
113
) { }
112
114
115
+ contentEffect = effect ( ( ) => {
116
+ this . destroyTooltipElement ( ) ;
117
+ this . content ( ) ? this . addTooltipElement ( ) : this . removeTooltipElement ( ) ;
118
+ } ) ;
119
+
113
120
ngAfterViewInit ( ) : void {
114
121
this . intersectionServiceSubscribe ( ) ;
115
122
}
@@ -197,13 +204,17 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit, AfterView
197
204
}
198
205
199
206
private addTooltipElement ( ) : void {
207
+ if ( ! this . content ( ) ) {
208
+ return ;
209
+ }
210
+
200
211
if ( ! this . tooltipRef ) {
201
212
this . createTooltipElement ( ) ;
202
213
}
203
214
204
215
this . tooltipId = this . getUID ( 'tooltip' ) ;
205
216
this . tooltipRef . instance . id = this . tooltipId ;
206
- this . tooltipRef . instance . content = this . content ;
217
+ this . tooltipRef . instance . content = this . content ( ) ;
207
218
208
219
this . tooltip = this . tooltipRef . location . nativeElement ;
209
220
this . renderer . addClass ( this . tooltip , 'd-none' ) ;
@@ -227,9 +238,9 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit, AfterView
227
238
this . changeDetectorRef . markForCheck ( ) ;
228
239
229
240
setTimeout ( ( ) => {
230
- this . tooltipRef . instance . visible = this . visible ;
231
- this . popperInstance . forceUpdate ( ) ;
232
- this . changeDetectorRef . markForCheck ( ) ;
241
+ this . tooltipRef && ( this . tooltipRef . instance . visible = this . visible ) ;
242
+ this . popperInstance ? .forceUpdate ( ) ;
243
+ this . changeDetectorRef ? .markForCheck ( ) ;
233
244
} , 100 ) ;
234
245
235
246
}
0 commit comments