@amin-karimi/ng2-tooltip-directive

中文文档
19.0.0发布于 2025/01/07MITTypeScriptES Module近 30 天下载 1860

Tooltip for Angular

原始使用文档
文档目录9 节
  1. Demo
  2. Installation
  3. Usage
  4. Set default values
  5. Properties
  6. Events
  7. Methods
  8. Author services
  9. Sponsors

Tooltip for Angular

V18.1.0 for Angular 18.0.1

V4.0.2 for Angular 17.3.7

V4.0.1 for Angular 17.0.9

V3.0.2 for Angular 16.0.5

V2.0.1 for Angular 15.0.4

V1.0.3 for Angular 14.2

Build Status

The tooltip is a pop-up tip that appears when you hover over an item or click on it.

🔬️ Help make Tooltips better by answering a few questions.

Demo

http://ivylab.space/tooltip

Installation

Install the npm package.

// npm i ng2-tooltip-directive

  npm i @amin-karimi/ng2-tooltip-directive

Import standalone:


import { TooltipDirective } from '@amin-karimi/ng2-tooltip-directive';
 
@Component({
    imports: [ TooltipDirective ]
}) 

Import Ng2Module:


import { TooltipModule } from '@amin-karimi/ng2-tooltip-directive';
 
@NgModule({
    imports: [ TooltipModule ]
}) 

Usage

Options can be set in the directive tag, so they have the highest priority.

<span tooltip="Tooltip" placement="top" showDelay="500">Tooltip on top</span>

You may pass as an object:

<span tooltip="Tooltip" [options]="myOptions">Tooltip on left</span>
myOptions = {
    'placement': 'left',
    'showDelay': 500
}

You can pass HTML as content :

<span tooltip="<p>Hello i'm a <strong>bold</strong> text!</p>">
  Tooltip with HTML content
</span>
<ng-template #HtmlContent>
  <p>Hello i'm a <strong>bold</strong> text!</p>
</ng-template>

<span [tooltip]="HtmlContent" contentType="template">
  Tooltip with template content
</span>

Set default values

Create a file with your settings, for example:

import { TooltipOptions } from 'ng2-tooltip-directive';

export const MyDefaultTooltipOptions: TooltipOptions = {
  'show-delay': 500
}

And pass your parameters when importing the module:

//import { TooltipModule, TooltipOptions } from 'ng2-tooltip-directive';
import { TooltipModule, TooltipOptions } from '@amin-karimi/ng2-tooltip-directive';
import { MyDefaultTooltipOptions } from './my-default-options';
 
@NgModule({
    imports: [ 
      TooltipModule.forRoot(MyDefaultTooltipOptions as TooltipOptions)
    ]
})

Properties

nametypedefaultdescription
placement"top", "bottom", "left", "right""top"The position of the tooltip.
autoPlacementbooleantruePlace the tooltip so that it does not go beyond the borders of the browser window.
showDelaynumber0The delay in ms before showing the tooltip.
hideDelaynumber300The delay in ms before removing the tooltip.
hideDelayTouchscreennumber0Delay in milliseconds before hiding the tooltip (for mobile devices).
displaybooleantrueTooltip availability for display.
displayTouchscreenbooleantrueDisplay the tooltip on mobile devices.
zIndexnumber0Z-index of the tooltip.
trigger"hover", "click""hover"Specifies how the tooltip is triggered. Control the closing time with "hide-delay".
tooltipClassstringClasses to be passed to the tooltip.
animationDurationnumber300The duration controls how long the animation takes to run from start to finish.
theme"dark", "light""dark"Theme of tooltip background and text.
shadowbooleantrueShadow of the tooltip.
offsetnumber8Offset the tooltip relative to the item.
widthnumberundefinedWidth of the tooltip.
maxWidthnumber200Maximum width of the tooltip.
contentType"string", "html', "template""string"The content type passed to the tooltip.
hideDelayAfterClicknumber2000Tooltip hiding delay for "click" trigger.
pointerEvents"auto", "none""none"Defines whether or not an element reacts to pointer events.
position{top: number, left: number}undefinedThe tooltip coordinates relative to the browser window.

Events

When you call events, the delays that are specified in the options in the directive are taken into account. Default delay before tooltip hiding is 300 milliseconds.

EventDescription
{type: "show", position: DOMRect}The event is called before the tooltip appears.
{type: "shown", position: DOMRect}The event is called after the animation of the appearance of the tooltip.
{type: "hide", position: DOMRect}The event is called before the tooltip is hidden.
{type: "hidden", position: DOMRect}The event is called after the animation of the tooltip is hidden.

Methods

If you specified the directive options, they will be taken into account when calling methods. Including the delay before the appearance and hiding of the tooltip.

MethodDescription
show()Shows the tooltip
hide()Hides the tooltip

Author services

Are you interested in this library but lacks features? Write to the author,(https://github.com/Amin-Karimi), he can do it for you.

Sponsors

We use Browserstack for cross-browser testing.

Browserstack

版本与发布记录

@amin-karimi/ng2-tooltip-directive 共发布 15 个版本,首次发布于 2022/12/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
19.0.0latest2025/01/071.8 年前
18.1.12024/08/022 年前
18.1.02024/08/022 年前
4.0.22024/05/082 年前
4.0.12024/01/152 年前
4.0.02024/01/152 年前

关于 @amin-karimi/ng2-tooltip-directive 的常见问题

@amin-karimi/ng2-tooltip-directive 是什么?

Tooltip for Angular

如何安装 @amin-karimi/ng2-tooltip-directive?

在项目目录运行 npm install @amin-karimi/ng2-tooltip-directive,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^19.0.5)、@angular/core(^19.0.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amin-karimi/ng2-tooltip-directive 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amin-karimi/ng2-tooltip-directive 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@amin-karimi/ng2-tooltip-directive 可以商用吗?

@amin-karimi/ng2-tooltip-directive 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amin-karimi/ng2-tooltip-directive 的下载量有多少?

根据 npm 官方下载统计,@amin-karimi/ng2-tooltip-directive 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,860 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amin-karimi/ng2-tooltip-directive 还在维护吗?

最新版本 19.0.0 发布于 2025/01/07(1.8 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。