javascript - How to render innerHTML of tag as nested HTML -


using angularjs making request receive json document. json document, after traversal, find array of additional json documents. more json traversal on each object in array, resulting inner json documents raw html.

i trying display each of raw htmls in page, however, can them raw text equivalent displayed mere text, not rendered in html.

using $sce in controller, can render 1 specific path on 1 specific element of array html correctly not of them.

here code:

//    controller: $scope.latestemails = function() {  $http.get('/emails/last/'+$scope.numberofemails).success(function(response) {     $scope.inserthtmlhere = $sce.trustashtml(response.body[0].body[0].content);         $scope.latestemails = response.body;     });  }  //    html <div ng-bind-html="inserthtmlhere"></div> <!-- works 1 given element -->         <ul>             <li ng-repeat="email in latestemails">{{email.body[0].content}} <!-- raw text displayed --></li>         </ul> 

the ng-bind-html correctly replaces first object in array's html. ng-repeat part places blocks of html text (not rendered html) in list (screenshot: http://i.imgur.com/swmz4xe.png).

is there way render html text received in ng-repeat full html? there different angularjs methodology use accomplish this?

any or advice appreciated!

after lot of loop , concatenation trickery found answer. loop through through array of html documents, concatenate each 1 , display concatenated html.

here solution code:

// controller:     $http.get('/emails/last/'+$scope.numberofemails).success(function(response) {     console.log('made latestemails request');     console.log(response);      // html of each email , concatenate     var concat;     for(var i=0; i<response.body.length; i++) {         var email = response.body[i].body[0].content;         concat+=email;     }     // display concatenated emails pure html     $scope.inserthtmlhere = $sce.trustashtml(concat); });  // html <div ng-bind-html="inserthtmlhere"></div> 

hope helps else comes across problem.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -