Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show tooltip on @ng-select/ng-select options

I am using @ng-select/[email protected] in my application and i have a very long text in array.

So, the complete text not visible in dropdown list so I want to show the title/ tooltip over the each and every options

I tried,

let listArray = [{name: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s'}];

<ng-select placeholder="Select" (change)="onChange($event)">
      <ng-option *ngFor="let list of listArray" 
       title="{{list.name}}"> {{list.name}} </ng-option>
 </ng-select>

But no luck

like image 487
Aniket Avhad Avatar asked Aug 04 '18 07:08

Aniket Avhad


3 Answers

This question is old, but using span could be another solution:

<ng-select placeholder="Select" (change)="onChange($event)">
    <ng-option *ngFor="let list of listArray" 
       title="{{list.name}}"><span [title]="list.name">{{list.name}}</span></ng-option>
</ng-select>
like image 182
mustafa küçük Avatar answered Oct 25 '22 11:10

mustafa küçük


you can achieve tooltip solution using below code

<ng-select [items]="listArray" bindLabel="name" bindValue="name">
    <ng-template ng-option-tmp let-item="item">
    <div title="{{item.name}}">{{item.name}}</div>
    </ng-template>
</ng-select>

Thanks

like image 39
Kaushik Andani Avatar answered Oct 25 '22 11:10

Kaushik Andani


You can put a template inside the <ng-option>, and add the directive ng-option-tmp:

<ng-select [items]="listArrayManyElements" placeholder="Select" [(ngModel)]="Selected" 
           bindLabel="name" bindValue="name">
    <ng-template ng-option-tmp let-item="item">
        <div [title]="item.name">{{item.name}}</div>
    </ng-template>
</ng-select>

I've updated your stackblitz

like image 22
Poul Kruijt Avatar answered Oct 25 '22 11:10

Poul Kruijt