diff --git a/front/core/directives/uvc.js b/front/core/directives/uvc.js index 45e04a27b..c881cf545 100644 --- a/front/core/directives/uvc.js +++ b/front/core/directives/uvc.js @@ -49,13 +49,26 @@ export function directive($http, $compile, vnApp, $translate) { } }); - let rule = selectors.join(', ') + '{display: none;}'; - if ($scope.css) - document.head.removeChild($scope.css); - $scope.css = document.createElement('style'); - document.head.appendChild($scope.css); - $scope.css.appendChild(document.createTextNode(rule)); + if ($scope.css || document.querySelector('style[id="uvc"]')) { + let child = document.querySelector('style[id="uvc"]'); + child.parentNode.removeChild(child); + } + + if (selectors.length) { + let rule = selectors.join(', ') + '{display: none;}'; + $scope.css = document.createElement('style'); + $scope.css.setAttribute('id', 'uvc'); + document.head.appendChild($scope.css); + $scope.css.appendChild(document.createTextNode(rule)); + } + + $scope.$on('$destroy', () => { + if ($scope.css && document.querySelector('style[id="uvc"]')) { + let child = document.querySelector('style[id="uvc"]'); + child.parentNode.removeChild(child); + } + }); } function saveConfiguration(tableConfiguration) {