问题:带有自定义 angularjs 指令和 kendoConconfirm 的剑道工具提示



我目前的情况:剑道工具提示单独工作正常。我使用kendoConfirm 的新自定义 Angularjs 指令单独工作正常。

但是一旦我尝试在一个元素上同时使用它们,那么只有剑道工具提示停止工作。

   <button type="button" title="Disable Item" k-confirm-disable k-confirm-disable-title="'Confirm Disable'" k-confirm-disable-msg="'Are you sure you want to disable this item?'" ng-click="disable(dataItem.id)"  class="btn btn-danger" kendo-tooltip k-content="'Disable Item'" k-options="kendoTooltipOptions">
 $scope.kendoTooltipOptions = {
showAfter: 600,     //time for tooltip appear
position : 'top',
width    : 100
}

剑道工具提示仅在我从元素中删除自定义角度指令时才有效。

function kConfirmDisable($compile){
return {
    restrict: 'A',
    scope: {
        kConfirmDisableTitle:   '@',
        kConfirmDisableMsg: '@'
    },
    link: function(scope, element, attrs){                      
        var clickHandlers = $._data(element[0]).events.click;
        clickHandlers.reverse(); //reverse the click event handlers list
        var onClick = function(evt) {                        
            evt.preventDefault();
            evt.stopImmediatePropagation();
            if(!scope.kConfirmDisableTitle) {
                scope.kConfirmDisableTitle = "Confirm";
            }
            if(!scope.kConfirmDisableMsg) {
                scope.kConfirmDisableMsg = "Are you sure?";
            }
            angular.element("<div></div>").kendoConfirm({
                title: scope.kConfirmDisableTitle.replace(/['"]+/g, ''),
                content: scope.kConfirmDisableMsg.replace(/['"]+/g, ''),
                buttonLayout: "normal",
                visible: false,
                actions: [
                     {
                        text: "No",
                        Primary: false,
                        action: function(){
                            evt.preventDefault();
                            evt.stopImmediatePropagation();                                
                        }
                    },
                    {
                        text: "Yes", 
                        Primary: true,
                        action: function(){                               
                            element.unbind(this);
                            setTimeout(function() {
                                element.unbind("click", onClick);
                                element.click();
                                evt.preventDefault();
                                evt.stopImmediatePropagation();
                                element.on("click", onClick);
                            },0);
                        }
                    },
                ],
                animation: {
                    open:{
                        effects: "zoom:in",
                        duration: 250
                    },
                    close:{
                        effects: "fade:out",
                        duration: 250
                    }
                },
                open: function(e) {
                   $("html, body").css("overflow", "hidden");
                },
                close: function() {
                    $("html, body").css("overflow", "visible");
                }
            }).data("kendoConfirm").open().result;
        };
        element.on("click", onClick);
        clickHandlers.reverse();
    }
}
}

由于Kendo AngularJs源代码不可用,我只能建议几件事:

  1. 尝试研究如果不停止传播并且不停止指令中的默认值会发生什么。如果情况是它不能立即在页面重新加载和悬停在元素上而不使用单击时工作 - 那么这无关紧要。

  2. 避免在指令中使用隔离作用域,并通过 $attrs link 函数参数获取属性。由于您没有指定得到js错误,因此我假设Kendo没有使用隔离范围,但这仍然是一个调查方向。

我的解决方案是我从"k-confirm-disable"指令中删除了"k-"并且它起作用了。我认为这是因为剑道保留了"K-"。

最新更新