Search results

Tooltip for Button in Angular Button component

22 Oct 2021 / 1 minute to read

Tooltip can be shown on button hover and it can be achieved by setting title attribute.

The following snippets illustrates how to show tooltip on button hover.

Source
Preview
app.component.ts
app.module.ts
main.ts
Copied to clipboard
import { Component, ViewChild, OnInit } from '@angular/core';
import { ButtonComponent } from '@syncfusion/ej2-angular-buttons';

@Component({
    selector: 'app-root',
    styleUrls:['styles.css'],
    template:  `<button #btn ejs-button [isPrimary]="true">Button</button>`
})

export class AppComponent implements OnInit {
  @ViewChild('btn')
  private btn: ButtonComponent;
  ngOnInit() {
    this.btn.element.setAttribute("title", "Primary Button")
  }
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);