Reputation:
This function getStudentsNames(item.students);
is returning a string as <br>Rom<br>Jay Clayton<br>Rom roy<br>
.
I tried replacing <br>
with \n
but didn't have any effect. I'm not able to get a line break so if any one could help. Thanks.
<span class="tooltiptext">{{getStudentsNames(item.students);}}</span>
Upvotes: 3
Views: 2799
Reputation: 27232
Try ngBindHtml directive.It evaluates the expression and inserts the resulting HTML into the element in a secure way.
DEMO
angular.module('myApp', ['ngSanitize'])
.controller('MyCtrl', function($scope) {
$scope.HTMLString = "<br>Rom<br>Jay Clayton<br>Rom roy<br>";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular-sanitize.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
<div ng-bind-html="HTMLString"></div>
</div>
Upvotes: 0
Reputation: 1644
You can use ng-bind-html for this.
angular.module("app",[]).controller("ctrl",function($scope){
$scope.htmlData = "<br>Rom<br>Jay Clayton<br>Rom roy<br>";
$scope.getStudentsNames = function(){
return this.htmlData;
}
}).filter('to_trusted', ['$sce', function($sce) {
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<span ng-app="app" ng-controller="ctrl" class="tooltiptext" ng-bind-html="getStudentsNames() | to_trusted"></span>
Upvotes: 1