So I have this directive which will allow use declaratively hide or show elements:
<div cdt-visible-to="Admin,Moderator">...</div>
So our HTML becomes as declarative as possible. And this is what our directive looks like:
eDiscovery.directive('cdtVisibleTo', ['AuthService', function (AuthService) {
return {
restrict: 'AE',
link: function ($scope, elem, attrs) {
let cdtArray = String(attrs['cdtVisibleTo'] || '')
.split(/[ ,]+/).map(i => String(i).trim()).filter(i => i);
let ln = cdtArray.length;
for (let i = 0; i < ln; i++) {
let r = cdtArray[i];
if(AuthService.hasPersona(r)){
elem.removeAttr('hidden');
return;
}
}
elem.attr('hidden', 'hidden');
}
}
}]);
So this is like a stand-in for ng-show
.
My question is - what would a stand-in for ng-if
look like?
What is the best way to remove elements from the DOM altogether with an Angular directive?