私のプロジェクトでmd-tabsを使用しています。カスタムディレクティブを追加して、そのタブを隠して表示します。私はスタイル表示を使用してmd-tabを非表示にする方法なし
<md-tabs md-dynamic-height md-border-bottom md-autoselect md-selected="quesCtrl.selectTab.activeMainTabIdx">
<md-tab label="question Add" ui-sref="questionsAdd">
<div ui-view class="marg-top30"></div>
</md-tab>
<md-tab label="upload Question" ui-sref="uploadQuestions">
<div ui-view class="marg-top30"></div>
</md-tab>
<md-tab label="My Questions" ui-sref="saved" ui-sref-opts="{reload: true, notify: true}">
<div ui-view class="marg-top30"></div>
</md-tab>
<div>
<md-tab has-permission="AUQUE" label="Author Questions" ui-sref="authorsubmitted" ui-sref-opts="{reload: true, notify: true}">
<div ui-view class="marg-top30"></div>
</md-tab>
</div>
</md-tabs>
の下に、次のように試してみましたが、私のディレクティブは
(function() {
'use strict';
angular.module('iceOnGo.Admin')
.directive('hasPermission', HasPermission);
function HasPermission(rPermissionService) {
return {
link: function (scope, element, attrs) {
if (!_.isString(attrs.hasPermission)) {
throw 'hasPermission value must be a string'
}
var value = attrs.hasPermission.trim();
var notPermissionFlag = value[0] === '!';
if (notPermissionFlag) {
value = value.slice(1).trim();
}
function toggleVisibilityBasedOnPermission() {
rPermissionService.HasPermissions(value).then(function (hasPermission) {
// if hasPermission is true then the element has to visible otherwise not
if (hasPermission && !notPermissionFlag || !hasPermission && notPermissionFlag) {
element[0].style.display = 'block';
}
else {
element[0].style.display = 'none';
}
});
}
toggleVisibilityBasedOnPermission();
scope.$on('permissionsChanged', toggleVisibilityBasedOnPermission);
}
};
}
HasPermission.$inject = [
'iceOnGo.RolePermissionsService'
];
})()のようなものです。
md-tab要素にはスタイル表示がありませんが、機能しません。どのようにこれを達成するか教えてください。どんな助けがありがたいですか?
ng-hideは、style.display:noneを入れるのと同じように、同じことをすることを願っています。 md-tabは受け付けませんstyle.display:none – MuruGan
新しいCSSクラスで!importantルールを試すことができます。 .my-hide { ディスプレイ:なし!重要; }「ng-hide」の代わりに「my-hide」を使用してください – Leandro