ユーザーが許可されているかどうかに基づいて、ツールチップ ( AngularJs Bootstrap UI から)を表示するディレクティブを作成したいと考えています。
それはうまく機能し、必要な属性を追加しますtooltip
がtooltip-position
、ツールチップは表示されません。
コードによって生成された要素と、通常の html としてツールチップを持つ要素を比較すると、class="ng-scope"
このクラスを手動で追加しても役に立たないことを除いて同じです。
ここに私のディレクティブコードがあります:
proGamersApp.directive('registered', ['$rootScope', 'authService', function ($rootScope, authService) {
return {
restrict: 'A',
scope: true,
link: function ($scope, element, attrs) {
element.addClass('faded');
$rootScope.$watch('user.role', function (role) {
$scope.$apply(function () {
var accessLevel = routingConfig.accessLevels[attrs.accessLevel];
if (!authService.authorize(accessLevel)) {
element.attr('tooltip-placement', 'bottom');
element.attr('tooltip', 'Avaiable for registered users.');
} else
element.attr('tooltip-placement', 'bottom');
element.attr('tooltip', 'Avaiable for registered users.');
});
});
}
};
}]);
誰かアイデアはありますか?
Update 3では、未定義の関数と書か
れているため ' が削除され$compile(element)
、$apply 関数の使用が変更されました。「$digest は既に進行中です」というエラーが引き続き発生します。
新しいコード:
proGamersApp.directive('registered', ['$rootScope', 'authService', function ($rootScope, authService, $compile) {
return {
restrict: 'A',
scope: true,
link: function ($scope, element, attrs) {
element.addClass('faded');
$rootScope.$watch('user.role', function (role) {
var accessLevel = routingConfig.accessLevels[attrs.accessLevel];
if (!authService.authorize(accessLevel)) {
element.attr('tooltip-placement', 'bottom');
element.attr('tooltip', 'Avaiable for registered users.');
} else {
element.attr('tooltip', 'Avaiable for registered users.');
}
$scope.$apply(element);
});
}
};
}]);