Angularjs отображать HTML в специальных символах

0

В моем последнем вопросе я был не очень ясен. Однако, увидев ответ с сервера, попросите его снова. Здесь html не отображается здесь, как исправить это

AppControllers.controller('create', ['$scope','$sce', function ($scope,$sce){
    var myhtml  = "<div class="modal-body " id="mymodal">
<form name="form" novalidate="" class="add-user">
<fieldset>";
    $scope.myhtml= $sce.trustAsHtml(myhtml)
    console.log($scope.myhtml)  
    /* Output of console.log
 <div class="modal-body " id="mymodal">
   <form name="ticketform" novalidate=""    class="add-user-from "&gt
    */ 
}

<div ng-bind-html="myhtml"></div>
Теги:

1 ответ

2
Лучший ответ

попробуйте что-то вроде этого,

Декодируйте строку html и передайте ее в ng-bind-html.

добавьте jquery.

var myhtml  = "&lt;div class=&quot;modal-body &quot; id=&quot;mymodal&quot;&gt;
&lt;form name=&quot;&quot; novalidate=&quot;&quot; class=&quot;add-user &quot;&gt;
&lt;fieldset&gt;";

$scope.decodedText = $('<textarea />').html(myhtml).text();


<div ng-bind-html="decodedText"></div>    

DEMO

ИЛИ Если вы предпочитаете No Jquery, используйте это,

var myhtml = "&lt;div class=&quot;modal-body &quot; id=&quot;mymodal&quot;&gt;&lt;form name=&quot;ticketform&quot; novalidate=&quot;&quot; class=&quot;add-user-from add_ticket&quot;&gt;&lt;fieldset&gt;";

var txt = document.createElement("textarea");
txt.innerHTML = myhtml;

$scope.decodedText = txt.value;

<div ng-bind-html="decodedText"></div>

DEMO

Ещё вопросы

Сообщество Overcoder
Наверх
Меню