简体   繁体   English

在angular 5中使用ng-select时如何添加工具提示?

[英]How to add Tooltip when use ng-select in angular 5?

I have used ng-select in dropdown, when user mouseover the dropdown list, it should show tooltip. 我在下拉菜单中使用了ng-select,当用户将鼠标悬停在下拉列表上时,它应该显示工具提示。 Code: 码:

<label>Grouping</label>
  <ng-select [items]="accounts"
            bindLabel="name"
            bindValue="name"
            groupBy="country"
            [(ngModel)]="selectedAccount">
  </ng-select>

Component 零件

 accounts = [
    { name: 'Adam', email: 'adam@email.com', age: 12, country: 'United States' },
    { name: 'Samantha', email: 'samantha@email.com', age: 30, country: 'United States' },
    { name: 'Amalie', email: 'amalie@email.com', age: 12, country: 'Argentina' },
    { name: 'Estefanía', email: 'estefania@email.com', age: 21, country: 'Argentina' },
    { name: 'Adrian', email: 'adrian@email.com', age: 21, country: 'Ecuador' },
    { name: 'Wladimir', email: 'wladimir@email.com', age: 30, country: 'Ecuador' },
    { name: 'Natasha', email: 'natasha@email.com', age: 54, country: 'Ecuador' }

];    

Note: I need tooltip in ng-select dropdown list. 注意:我需要ng-select下拉列表中的工具提示。

I tried with title attribute, but it not working. 我尝试使用title属性,但是它不起作用。

Example: 例:

When user mouse over the dropdown list, need to show ToolTip. 当用户将鼠标悬停在下拉列表上时,需要显示工具提示。

Question

How to add tootip in ng-select using angular5? 如何使用angular5在ng-select中添加tootip?

Your suggestion will helpful for me. 您的建议将对我有所帮助。

Use *ngFor to create options and give options the tooltip which you need. 使用*ngFor创建options并为选项提供所需的工具提示。 check this Example 检查这个例子

you can use ng-template to achive this 您可以使用ng-template实现

<ng-select [items]="accounts"
                bindLabel="name"
                bindValue="name"
                groupBy="country"
                [(ngModel)]="selectedAccount">

        <ng-template ng-option-tmp let-item="item">
        <div title="{{item.name}}">{{item.name}}</div>
        </ng-template>
    </ng-select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM