Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the raw HTML in angularjs using the $http directive?

Tags:

angularjs

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.

like image 581
john smith Avatar asked Oct 08 '13 01:10

john smith


2 Answers

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;
});
like image 125
J. Bruni Avatar answered Nov 03 '22 00:11

J. Bruni


add ngSanitize

inject $sce and use

$scope.rawHtml = $sce.trustAsHtml(html)
<div ng-bind-html="rawHtml"> <div>
like image 24
Jason Als Avatar answered Nov 02 '22 22:11

Jason Als