-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathangular-bind-html-compile.js
31 lines (28 loc) · 1.19 KB
/
angular-bind-html-compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function (angular) {
'use strict';
var bindHtmlCompile = angular.module('angular-bind-html-compile', []);
bindHtmlCompile.directive('bindHtmlCompile', ['$compile', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(function () {
return scope.$eval(attrs.bindHtmlCompile);
}, function (value) {
// In case value is a TrustedValueHolderType, sometimes it
// needs to be explicitly called into a string in order to
// get the HTML string.
element.html(value && value.toString());
// If scope is provided use it, otherwise use parent scope
var compileScope = scope;
if (attrs.bindHtmlScope) {
compileScope = scope.$eval(attrs.bindHtmlScope);
}
$compile(element.contents())(compileScope);
});
}
};
}]);
if (typeof module !== 'undefined' && module.exports) {
module.exports = bindHtmlCompile.name;
}
}(window.angular));