ng-classを使用して 'class'ディレクティブをロードしようとしています。私の指示がロードされることはありません。このディレクティブは多目的ディレクティブです。このディレクティブは独立したスコープを作成したくありません。 ng-classの条件に基づいて、必要なときにのみロードされるため、attributeまたはelementディレクティブは使用されません。誰もこれをやろうとして成功しましたか?ng-classを使用してディレクティブをロードするとクラスディレクティブが動作しない
<div ng-class="someClass {{tooltip: enabled}}"></div>
ここではenabled
はスコープ変数です。
app.directive('tooltip', ['$timeout', '$location', '$rootScope', function (timer, $location, $rootScope) {
return {
restrict: 'C',
transclude: true,
link: function (scope, element) {
var printContent = function() {
/* uses the content of .tooltip-content if it is a complex html tooltip,
otherwise
you can use the title attribute for plaintext tooltips
*/
var tooltipContent = $(element).find('.tooltip-content').html();
if (!tooltipContent) {
tooltipContent = $(element).attr('title');
}
$(element).tooltip({
content: tooltipContent,
items: "img, a, span, button, div",
tooltipClass: "tooltip",
position: { my: "left+30 top", at: "right top", collision: "flipfit" },
show: { effect: "fadeIn", duration: "fast" },
hide: { effect: "fadeOut", duration: "fast" },
open: function (event, ui) { $rootScope.tooltipElement = event.target; }
});
};
timer(printContent, 0);
}
};
}]);
あなたは設定を忘れているかもしれません: 'restrict: 'C''? – Cherniv
そのセット。私のポストへの更新を見てください。 – vaibinewbee
がこの構文を試しているかもしれません: 'class =" someClass "ng-class =" {tooltip:enabled} "' – Cherniv