mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-30 13:00:29 +00:00
25 lines
824 B
JavaScript
25 lines
824 B
JavaScript
'use strict';
|
|
|
|
|
|
/**
|
|
* @ngdoc directive
|
|
* @name ngSanitize.directive:ngBindHtml
|
|
*
|
|
* @description
|
|
* Creates a binding that will sanitize the result of evaluating the `expression` with the
|
|
* {@link ngSanitize.$sanitize $sanitize} service and innerHTML the result into the current element.
|
|
*
|
|
* See {@link ngSanitize.$sanitize $sanitize} docs for examples.
|
|
*
|
|
* @element ANY
|
|
* @param {expression} ngBindHtml {@link guide/expression Expression} to evaluate.
|
|
*/
|
|
angular.module('ngSanitize').directive('ngBindHtml', ['$sanitize', function($sanitize) {
|
|
return function(scope, element, attr) {
|
|
element.addClass('ng-binding').data('$binding', attr.ngBindHtml);
|
|
scope.$watch(attr.ngBindHtml, function ngBindHtmlWatchAction(value) {
|
|
value = $sanitize(value);
|
|
element.html(value || '');
|
|
});
|
|
};
|
|
}]);
|