angular.module("esNgAntd").directive("antdSlot", function ($compile) { return { controllerAs: "antdSlot", restrict: "E", transclude: true, replace: true, scope: { content: "@", context: "=", }, controller: function ($scope, $element, $attrs) { this.getContext = function () { return $scope; }; $scope.watch = { content: (newValue) => { if (newValue !== undefined) { if (/<[^>]+>/.test(newValue)) { $scope.parentElement .empty() .append( $compile(newValue)( $scope.context ? $scope.context : $scope ) ); } else { $element.text(newValue); } } }, }; for (const key in $scope.watch) { $scope.$watch(key, $scope.watch[key], true); } }, link: function ($scope, $element, $attrs, $controllers, $transclude) { $scope.parentElement = $element.parent(); }, }; });