1

There is a mce textarea used to save formated text. After save I want to show the exact format used by user. Formats like bolds and italic are hold without text-decoration and it does work properly.

The problem raises when user format strikethrough or underline. I found a very close question AngularJS: Bind html string with custom style and I tried use trustAsHtml after injected it in my controller.

To make short the question, the output text is like:

(function(angular) {
  'use strict';
angular.module('bindHtmlExample', ['ngSanitize'])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.myHTML =
       '<span style="text-decoration: underline;">this does not work</span> ' +
       '<u>this work</u> ';
  }]);
})(window.angular);

When I use trustAsHtml no data is showed at all. PS.: I understand I injected properly:

My controller:

(function () {
  angular
    .module(myApp')
    .controller('myController', myController);

  myController.$inject = ['$sce', ...'];

  function myController($sce, ...) {
    var vm = this;

    vm.promise = {};

    vm.trustAsHtml = trustAsHtml;
...
    function trustAsHtml(string) {
      return $sce.trustAsHtml($sce.parseAsHtml(string));
    };
Kim Kern
  • 54,283
  • 17
  • 197
  • 195
DemeCarvO
  • 487
  • 4
  • 16
  • 28
  • 1
    You should do it by creating a directive for it instead of misusing a controller. – lin Jun 14 '17 at 10:03

0 Answers0