天天看点

angularjs给文本赋值保留换行符br的方法

场景:后台放回一串数据带有换行符 <br />,使用angularjs的时候,它会把换行符直接显示储来,不会换行。

解决方法:html标签增加

ng-bind-html="mycontent"      
<div ng-bind-html="mycontent" style="margin-left: 280px;margin-right: 280px"></div>
           

 js代码中引入:$sce

app.controller('myCon1', ["$scope", "$http", "$filter", "NgTableParams","$sce", function ($scope, $http, $filter, NgTableParams,$sce) {
      ...省略

  $scope.mycontent= $sce.trustAsHtml(response.data);
   ...
           

ok,成功实现换行。