【问题标题】:Using Tooltipster Jquery Plugin in Angular js在 Angular js 中使用 Tooltipster Jquery 插件
【发布时间】:2015-08-25 09:04:47
【问题描述】:

我有一个表格,悬停在特定单元格上时,我需要根据它悬停的单元格显示具有不同值的工具提示。

我想知道如何以 Angular 方式使用该插件,但我在现有设计中遇到了问题。

问题:

-它在第一次悬停时不起作用。

-在第二次悬停时工具提示器仅显示它为所有单元格悬停的第一个值。值没有改变

-它应该显示有时间的 associateID

 $scope.SwipeDataDetails = function (associateid) {               
                $('.tooltip').tooltipster({
                    content: $('<div class="swipePopup"><div class="arrowPop"></div><div class="swipePopDetails"><div class="swipeContent1 fLeft"><img src="../images/Swipe_in.png"/> Swipe-In Time</div><div class="swipeContent2 fRight">' + associateid + '10:00AM' + '</div></div><div class="swipePopDetails"><div class="swipeContent1 fLeft"><img src="../images/Swipe_out.png"/> Swipe-Out Time</div><div class="swipeContent2 fRight">' + associateid + '11:00AM' + '</div></div><div class="swipePopDetailsTotal"><div class="swipeContent1 fLeft">Total Swipe Hours</div><div class="swipeContent2 fRight">' + associateid + '1.0' + '</div></div></div>'),                        
                    position: 'left',
                    offsetX: 0,
                    multiple:true
                });
        };

在控制台中出现错误,如

Tooltipster: one or more tooltips are already attached to this element: ignoring. Use the "multiple" option to attach more tooltips.

这是我的Plunker

但我的要求是不要使用多个工具提示,在悬停在特定单元格上时更改现有工具提示的值。

当附加多个选项时,它第一次不起作用。

不确定这是在 Angular js 中使用 jquery 插件的正确方法。 寻找在 Angular js 中使用 jquery 插件的拇指规则/步骤/程序。

请指导我,或者有没有更好的方法来实现这一点。我是 Angular js 的新手。

【问题讨论】:

  • 你找到这个答案了吗?我有同样的问题。

标签: javascript jquery angularjs tooltipster


【解决方案1】:

我已经编写了一个指令来使用很棒的 Tooltipster。

用法示例:

1) 在顶部显示工具提示(默认位置):

<a href="#" sb-apa-tooltip tooltip-content="Items Browser">

2) 在左侧显示工具提示,maxWidth == 400px:

<a href="#" sb-apa-tooltip tooltip-content="hello<br>my friend" tooltip-position="left" tooltip-max-width="400">

sbApaTooltipDirective.js

(function() {

    angular
        .module('apa-tooltip-directive', [])
        .directive('sbApaTooltip', [function() {
        return {
            restrict: 'A',
            link: function(scope, element, attrs) {
                var position = attrs.tooltipPosition ? attrs.tooltipPosition : 'top';
                var maxWidth = attrs.tooltipMaxWidth ? attrs.tooltipMaxWidth : null;

                element.tooltipster({
                    position: position,
                    content: angular.element('<div>' + attrs.tooltipContent + '</div>'),
                    maxWidth: maxWidth
                });
            }
        }
    }]);

})();

【讨论】:

    【解决方案2】:

    我用下面的方法来解决这个问题:

    http://codepen.io/jedfras/pen/KqiEb

    以下是我的指令:

    app_.directive('popOver', ['myFactory', function (mf) {
        return {
            restrict: 'C',
            link: function (scope, element, attr) {
                setTimeout(function () {
                    element.
                    bind('mouseenter', function (e) {
                        element.inUpdate = true;
                        if (attr != null && attr.content !== null && attr.content !== "") {
                            mf.ToolTip(attr.content).success(function (data) {
                                hideSpinner();
                                element.tooltipster({
                                    content: angular.element('<span>' + data + '</span>&nbsp;<span><a target=_blank href=' + '"http://google.com"' + '</a>More Help..</span>'),
                                    contentAsHTML: true,
                                    interactive: true,
                                    multiple: true,
                                    animation: 'grow',
                                    trigger: 'click',
                                    delay: 100,
                                    maxWidth: 500,
                                    speed: 300
                                });
                                element.tooltipster('show');
                                element.inUpdate = false;
    
                            });
                        }
    
                    }).
                    bind('mouseleave', function (e) {
                        hideTooltipster(element);
                    });
    
                }, 400);
            }
        };
    }]);
    

    下面是我的工厂:

    app_.factory('myFactory', ['$http', function ($http) {
        function getToolTip(query) {
            //get the Tooltip based on query element
            return $http.get("api/User/GetToolTip/" + query + "/" + misc_.guid());
        }
        return {
            ToolTip: getToolTip
        };
    }])
    

    HTML:

    <span class="pop-over" data-content="{{ qItem.fieldCaptionDetails }}">{{ qItem.fieldCaption }}</span>
    

    评论:

    我们需要多个选项。用户鼠标悬停时将显示工具提示。如果他们想要进行任何交互,那么他们需要点击元素,这样工具提示才会保留。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多