redash/client/app/components/transclude-replace.js
2018-11-20 23:34:37 +02:00

27 lines
640 B
JavaScript

export default function init(ngModule) {
ngModule.directive('ngTranscludeReplace', $log => ({
terminal: true,
restrict: 'EA',
link: ($scope, $element, $attr, ctrl, transclude) => {
if (!transclude) {
$log.error(
'orphan',
'Illegal use of ngTranscludeReplace directive in the template! ' +
'No parent directive that requires a transclusion found.',
);
return;
}
transclude((clone) => {
if (clone.length) {
$element.replaceWith(clone);
} else {
$element.remove();
}
});
},
}));
}
init.init = true;