简体   繁体   English

ngRepeat删除工具提示样式

[英]ngRepeat removes tooltip styling

Thanks in advance for any help. 在此先感谢您的帮助。

I have a jquery tooltip that is styled, but when it is used in an ngRepeat the custom styling of the tooltip is removed and I'm not sure why. 我有一个样式化的jquery工具提示,但是在ngRepeat中使用它时,该工具提示的自定义样式已删除,我不确定为什么。

Examples: 例子:

Tooltip shows up with correct styling: 工具提示显示正确的样式:

<div class="toggle">
    <input type="checkbox" id="amount_{{i.ProductCode}}" name="amount" data-ng-model="$parent.amount" value="{{i.ProductCode}}" data-ng-required="1" /> 
    Hello&nbsp;<span class="info-tip" title="World!"></span>
</div>

Tooltip shows up with default styling: 工具提示显示为默认样式:

<div data-ng-repeat="i in options.amounts" data-ng-cloak="">
    <div class="toggle">
        <input type="checkbox" id="amount_{{i.ProductCode}}" name="amount" data-ng-model="$parent.amount" value="{{i.ProductCode}}" data-ng-required="1" /> 
        Hello&nbsp;<span class="info-tip" title="World!"></span>
    </div>
</div>

I've spent quite a while looking into it, and from what I can gather from my research it seems to be an ngRepeat scoping issue. 我花了很长时间研究它,从我的研究中可以发现,这似乎是一个ngRepeat作用域问题。 However I'm not certain that this is the issue and I'm not sure how to go about fixing it if it is (hence coming here). 但是,我不确定这是问题所在,并且不确定如何解决(因此来了)。 Ideally I would like to use ngRepeat and maintain my custom tooltip styling. 理想情况下,我想使用ngRepeat并保持我的自定义工具提示样式。

Any guidance is appreciated, thanks! 任何指导表示赞赏,谢谢!

The solution was to "refresh" the dynamic elements in the repeater after the repeater has been initialised and rendered. 解决方案是在初始化并渲染中继器后,“刷新”中继器中的动态元素。

Create new directive to broadcast when the ngRepeat has finished rendering: 创建新指令以在ngRepeat完成渲染后进行广播:

app.directive('onFinishRender', ["$timeout",function ($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element, attr) {
            if (scope.$last === true) {
                $timeout(function() {
                    scope.$emit('ngRepeatFinished');
                });
            }
        }
    };
}]);

In the controller create a listener for the broadcast that then updates the parent of the tooltip (which in turn updates the tooltip): 在控制器中,为广播创建一个侦听器,然后更新工具提示的父级(后者又更新工具提示):

$scope.$on('ngRepeatFinished', function (e) {
        window.hbf.angular.components.byName("components/Tooltip")
            .update($('.parentClass'));
    });

Add 'on-finish-render="ngRepeatFinished"' to the ngRepeat in the ascx: 将'on-finish-render =“ ngRepeatFinished”'添加到ascx中的ngRepeat中:

<div data-ng-repeat="i in items" data-ng-cloak="" on-finish-render="ngRepeatFinished">

Reasoning : On the page load event the jQuery binds the custom tooltip class to tooltip function. 推理 :在页面加载事件中,jQuery将自定义工具提示类绑定到工具提示功能。 However, when it's used in the repeater the event is fired after the page load and there is no existing binding. 但是,当在转发器中使用该事件时,将在页面加载后触发该事件,并且不存在任何绑定。 Therefore it is necessary to bind newly created elements to the tooltip again to "refresh" them and have them display. 因此,有必要再次将新创建的元素绑定到工具提示,以“刷新”它们并使它们显示。

Basically the jQuery is initialised and rendered, but the ngRepeat is on the client side. 基本上,jQuery是初始化和呈现的,但是ngRepeat在客户端。 Each repeat is dynamically generated with the scope of the child, not the parent, so all original bindings are out of scope and need to be re-binded after the ngRepeat has been created. 每个重复都是在子范围(而不是父范围)的范围内动态生成的,因此所有原始绑定都超出范围,因此在创建ngRepeat之后需要重新绑定。

If anyone wants more info on how I went about this I posted it on my development blog which you can find here . 如果有人想了解我如何做的更多信息,我将其发布在我的开发博客上 ,您可以在这里找到。

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

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