After numerous attempts, I experimented with concealing the tooltip based on a condition in ng2-tooltip-directive
. Unfortunately, this functionality is only available in the Pro version which offers element selection and additional features.
Alternatively, there are several excellent tooltip libraries accessible for Angular material design.
Note: It is not advisable to use
*ngIf title and tooltip=""
when iterating through items as it leads to unnecessary code duplication.
If you are utilizing bootstrap in your project, consider using ngbTooltip
:
npm module
@ng-bootstrap/ng-bootstrap
app.module.ts
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
imports: [
....
NgbModule,
....
]
.html
<ng-template #TooltipContent>
<div>This file belongs to <b>
{{file.owner.name}}</b>
</div>
</ng-template>
<div *ngFor="let file of files">
.....
<div [ngbTooltip]="file.owner.name ? TooltipContent : ''">
.....
.....
</div>
.....
.....
</div>
In the illustrated example above, the tooltip will only be displayed if the file has an owner.