Remove html tags from content - ajax call AngularJs

520 views
Skip to first unread message

prem Kumar

unread,
Oct 20, 2014, 3:36:37 AM10/20/14
to ang...@googlegroups.com
Hi,

I am new AngularJS. Need to get html content through ajax call in agulurJS.

When trying to display the result in table, it also displaying the tag with class name..

Here is my example,

<table>
<tr>
    <th>Name</th>
    <th>City</th>
    <th>Country</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.Name}}</td>
<td>{{x.City | uppercase}}</td>
<td>{{x.Country}}</td>
</tr>
</table>
<script type="text/javascript">

var app = angular.module('myApp',[]);

app.controller('myController',function($scope,$http){

$http.get("response.php").success(function(response) {
    $scope.names = response;
});
});
</script>

Response.php:
<?php

$arr = array(array('Name'=>'<span class="sample">test</span>','City'=>'test','Country'=>'test'));

echo json_encode($arr);
?>


Thanks.

Anton Trapp

unread,
Oct 21, 2014, 2:36:08 AM10/21/14
to ang...@googlegroups.com
Haven't tried it, but first guess: security problem.

Try to use ng-bind-html.

prem Kumar

unread,
Oct 21, 2014, 5:56:22 AM10/21/14
to ang...@googlegroups.com

Hi Anton Trapp,

thanks for your reply.. I have used ng-bind-html to display html content and it is working fine...

<td ng-bind-html="display_html_content(x.Name)">
</td>

$scope.display_html_content = function(snippet) {
  return $sce.trustAsHtml(snippet);
};
Reply all
Reply to author
Forward
0 new messages