Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit c41fe86

Browse files
committed
Refactored the "compile" directive, reduced code
re: https://stackoverflow.com/a/29994559/12787
1 parent a784dd6 commit c41fe86

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed
Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
angular.module("umbraco.directives").directive("dtgeBindHtmlCompile", [
2-
3-
"$compile",
4-
5-
function ($compile) {
6-
7-
var directive = {
8-
restrict: "A",
9-
scope: {
10-
dtgeBindHtmlCompile: "="
11-
},
12-
link: function ($scope, $element, $attrs) {
13-
$scope.$watch(function () { return $scope.dtgeBindHtmlCompile }, function (newValue, oldValue) {
14-
$element.html(newValue);
15-
16-
// Only compile child nodes to avoid starting an infinite loop
17-
var childNodes = $element.contents();
18-
$compile(childNodes)($scope);
19-
});
20-
}
21-
};
22-
23-
return directive;
24-
}
25-
]);
1+
angular.module("umbraco.directives").directive("dtgeBindHtmlCompile", ["$compile", function ($compile) {
2+
return {
3+
restrict: "A",
4+
link: function (scope, element, attrs) {
5+
scope.$watch(function () {
6+
return scope.$eval(attrs.dtgeBindHtmlCompile);
7+
}, function (value) {
8+
element.html(value);
9+
$compile(element.contents())(scope);
10+
});
11+
}
12+
};
13+
}]);

0 commit comments

Comments
 (0)