2

i have this html in my database.

<p>my data here. <b>bold a bit</b></p>

the database from factory like this

.factory('DataSingle', function($http, $q){
  var sContent = function(idc){
    var deferred = $q.defer();
    $http.get('http://mydomainrestserver/'+idc)
    .success(function(data, status, headers, config){
     deferred.resolve(data);
    });
     return deferred.promise;
  }
 return { sContent : sContent }
})

this is my controller

.controller('SingleCtrl', function($scope, $http, DataSingle, $stateParams){
 var single_id = $stateParams.ids;
 DataSingle.sContent(single_id).then(

 function(single){
  $scope.singledata = single;
   }
})

singe the data is from database. it render as text instead of rendering it with paragraph and bold text.

what i get is just plain test from the view

Title: Single page
Data: <p>my data here. <b>bold a bit</b></p>

the data is successfully received but not rendered properly on my device. the question is, how to render the html from the result of query to ionic content view?

2 Answers 2

4

in factory

$scope.singledata = $sce.trustAsHtml(single);

in html

<span ng-bind-html="singledata" class="htmlComment"></span>
Sign up to request clarification or add additional context in comments.

Comments

1

Obviously all text content is escaped for security reasons unless you explicitely mark it as safe using the $sce service. So what you should do is: 

$scope.singledata = $sce.trustAsHtml(single);

https://docs.angularjs.org/api/ng/service/$sce

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.