11

I'm currently using $http.get to retrieve the data from the backend. The data received is actually in HTML format; however, it comes back escaped with \t\n and all the white spaces. If I were to perform the same $.get request using jQuery, the data that comes back comes unescaped. Anyway how I can use get the raw unescaped HTML? I've tried $sce.trustAsHtml with no avail.

4
  • Then use jQuery. But seriously, is there a reason that you need to use $http.get? Commented Oct 8, 2013 at 1:20
  • 3
    I'm trying to not use jQuery at all and use angularjs library so I don't have to load in both. Commented Oct 8, 2013 at 1:46
  • Are you retrieving an html file or html as text from the server? Commented Oct 8, 2013 at 2:15
  • as text from the server Commented Oct 11, 2013 at 8:18

2 Answers 2

11

I don't know how you are getting the response, because you have not shared any code.

How are you getting the data?

I use $http to get raw HTML templates without any issue:

$http.get('url').then(function(response) {
    var raw_html = response.data;
});
Sign up to request clarification or add additional context in comments.

3 Comments

for some odd reason, i get escaped HTML as a response regardless if I use $sce or not.
Maybe it is coming escaped from the server... can you inspect what is coming from the server? (Using Chrome developer tools, Firebug, or other tool...)
@AniketSinha: None, actually. I am used to code in PHP. Just this. I will remove the $.
9

add ngSanitize

inject $sce and use

$scope.rawHtml = $sce.trustAsHtml(html)
<div ng-bind-html="rawHtml"> <div>

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.