55 ElementRef ,
66 HostBinding ,
77 Inject ,
8- Input , OnChanges ,
8+ Input ,
9+ OnChanges ,
910 OnDestroy ,
1011 OnInit ,
1112 Renderer2 ,
@@ -39,10 +40,11 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
3940 */
4041 @Input ( 'cTooltipOptions' )
4142 set popperOptions ( value : Partial < Options > ) {
42- this . _popperOptions = { ...this . _popperOptions , placement : this . placement , ...value } ;
43+ this . _popperOptions = { ...this . _popperOptions , placement : this . placement , ...value } ;
4344 } ;
45+
4446 get popperOptions ( ) : Partial < Options > {
45- return { placement : this . placement , ...this . _popperOptions } ;
47+ return { placement : this . placement , ...this . _popperOptions } ;
4648 }
4749
4850 /**
@@ -61,12 +63,12 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
6163 @Input ( 'cTooltipVisible' )
6264 set visible ( value : boolean ) {
6365 this . _visible = value ;
64- value ? this . addTooltipElement ( ) : this . removeTooltipElement ( ) ;
65- this . tooltipRef ?. changeDetectorRef . markForCheck ( ) ;
6666 }
67+
6768 get visible ( ) {
6869 return this . _visible ;
6970 }
71+
7072 private _visible = false ;
7173
7274 @HostBinding ( 'attr.aria-describedby' ) get ariaDescribedBy ( ) : string | null {
@@ -83,10 +85,10 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
8385 {
8486 name : 'offset' ,
8587 options : {
86- offset : [ 0 , 0 ] ,
87- } ,
88- } ,
89- ] ,
88+ offset : [ 0 , 0 ]
89+ }
90+ }
91+ ]
9092 } ;
9193
9294 constructor (
@@ -110,7 +112,6 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
110112 }
111113
112114 ngOnInit ( ) : void {
113- // this.createTooltipElement();
114115 this . setListeners ( ) ;
115116 }
116117
@@ -120,15 +121,18 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
120121 trigger : this . trigger ,
121122 callbackToggle : ( ) => {
122123 this . visible = ! this . visible ;
124+ this . visible ? this . addTooltipElement ( ) : this . removeTooltipElement ( ) ;
123125 } ,
124126 callbackOff : ( ) => {
125127 this . visible = false ;
128+ this . removeTooltipElement ( ) ;
126129 } ,
127130 callbackOn : ( ) => {
128131 this . visible = true ;
132+ this . addTooltipElement ( ) ;
129133 }
130- }
131- this . listenersService . setListeners ( config )
134+ } ;
135+ this . listenersService . setListeners ( config ) ;
132136 }
133137
134138 private clearListeners ( ) : void {
@@ -146,8 +150,11 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
146150
147151 private createTooltipElement ( ) : void {
148152 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();
151158 }
152159 }
153160
@@ -167,34 +174,34 @@ export class TooltipDirective implements OnChanges, OnDestroy, OnInit {
167174 }
168175 this . tooltipRef . instance . content = this . content ;
169176 this . tooltip = this . tooltipRef . location . nativeElement ;
177+ this . renderer . addClass ( this . tooltip , 'fade' ) ;
170178
171179 setTimeout ( ( ) => {
172180 this . popperInstance = createPopper (
173181 this . hostElement . nativeElement ,
174182 this . tooltip ,
175183 { ...this . popperOptions }
176184 ) ;
185+ this . viewContainerRef . insert ( this . tooltipRef . hostView ) ;
177186 setTimeout ( ( ) => {
178187 this . tooltipId = this . getUID ( 'tooltip' ) ;
179188 this . tooltipRef . instance . id = this . tooltipId ;
180189 this . tooltipRef . instance . visible = this . visible ;
181190 this . renderer . appendChild ( this . document . body , this . tooltip ) ;
182191 this . popperInstance . forceUpdate ( ) ;
183- this . tooltipRef . changeDetectorRef . markForCheck ( ) ;
184- // this.tooltipRef.changeDetectorRef.detectChanges();
192+ // this.tooltipRef.changeDetectorRef.markForCheck();
185193 } , 100 ) ;
186- } )
194+ } ) ;
187195 }
188196
189197 private removeTooltipElement ( ) : void {
190198 if ( ! this . tooltipRef ) {
191- return
199+ return ;
192200 }
193201 this . tooltipRef . instance . visible = this . visible ;
202+ this . tooltipRef . instance . id = undefined ;
194203 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 ( ) ;
198205 this . popperInstance ?. destroy ( ) ;
199206 this . tooltipId = '' ;
200207 } , 300 ) ;
0 commit comments