首页 > 解决方案 > 有没有办法在 Angular Js 自定义指令中添加“uib-tooltip-html”作为属性?

问题描述

我创建了一个 AngularJS 自定义指令来更改元素的文本。

 angular.module('main').directive('showAB', ["$sce", "$compile", ($sce, $compile) => {
    return {
        restrict: 'A',
        scope : {
            textA: "=",
            textB: "=",
            showA: "="
        },
        link: (scope, $elem, attrs) => {

            var displayText = !scope.showA ? scope.textA : scope.textB;
            $elem.html(displayText);
            $elem.removeAttr("show-a-b");
            $elem.attr("uib-tooltip-html", displayText);
            $compile($elem)(scope);
        }

    }
}]);

这不是实际的代码,只是创建了一个简单的指令来解释这个问题。它将根据 showA 变量显示 textA 或 textB。以 html 格式显示的文本应显示为该元素的工具提示。

有没有办法做到这一点?如果我用 uib-tooltib 替换 uib-tooltip-html,它工作正常,但由于文本是 html,它不会在屏幕上正确显示值。

标签: angularjsangular-ui

解决方案


推荐阅读