How To Use Data-Balloon In Angular

Today we are going to discuss how to use data-balloon in the angular 2/4 application. You must know why we are using data-balloon in our application and what kind of features it is going to provide to us. For this click on this link and check out its features.

It is easy to use in simple HTML applications, but we have a problem to use this in the angular 2/4 application. In the angular 2/4, we can't use this as it is as shown in the above article. For this, we need to create a directive and use that under our application. I am going to explain how to create directive and how to use this in the application.

Step by step information

  1. Create a new TS file or use an existing file to create the directive and copy the below code. In this code, you will find that we are going to set only two properties as dynamic, following the same method you can add other properties and make it more stylish.
    1. // This directive is to use to add the hover message using data-balloon  
    2. @Directive({  
    3.     selector: '[dataBalloon]'  
    4. })  
    5. export class DataBalloonDirective implements OnChanges {  
    6.     @Input('databalloonProperty') tooltipText: any;  
    7.     @Input('databalloonpos') position: any;  
    8.     constructor(private el: ElementRef) {}  
    9.     ngOnChanges(changes) {  
    10.         if (this.tooltipText) {  
    11.             $(this.el.nativeElement).attr({  
    12.                 "data-balloon"this.tooltipText,  
    13.                 "data-balloon-pos"this.position,  
    14.                 "data-balloon-length""fit"  
    15.             });  
    16.         }  
    17.     }  
    18. }  
  2. Add that directive in your app-common module or on your page where you want to use this

  3. <span class="text-capitalize"dataBalloon databalloonProperty="{{username}}" databalloonpos="up">

  4. Run the application and check the results.