Advertisement
kotvalera83

output HTML within AngularJS

Jun 12th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div ng-bind-html-unsafe="group.description"></div>
  2.  
  3.  
  4. .directive('ngBindHtmlUnsafe', ['$sce', function($sce){
  5.     return {
  6.         scope: {
  7.             ngBindHtmlUnsafe: '=',
  8.         },
  9.         template: "<div ng-bind-html='trustedHtml'></div>",
  10.         link: function($scope, iElm, iAttrs, controller) {
  11.             $scope.updateView = function() {
  12.                 $scope.trustedHtml = $sce.trustAsHtml($scope.ngBindHtmlUnsafe);
  13.             }
  14.  
  15.             $scope.$watch('ngBindHtmlUnsafe', function(newVal, oldVal) {
  16.                 $scope.updateView(newVal);
  17.             });
  18.         }
  19.     };
  20. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement