Slot.js
752 Bytes
angular.module("esNgAntd").directive("antdSlot", ["$compile", function ($compile) {
return {
restrict: "E",
replace: true,
transclude: true,
scope: {
content: "@",
context: "="
},
controller: function ($scope, $element) {
$scope.watch = {
content: function (newVal) {
if (newVal !== undefined) {
if (/<[^>]+>/.test(newVal)) {
$element.replaceWith($compile(newVal)($scope.context ? $scope.context : $scope));
} else {
$element.text(newVal);
}
}
}
};
},
link: function ($scope) {
for (const key in $scope.watch) {
$scope.$watch(key, $scope.watch[key], true);
}
}
};
}]);