在插值绑定中向字符串添加新行

时间:2018-11-26 10:27:18

标签: javascript angularjs string binding interpolation

如何在字符串中添加新行:

HTML:

 <div class="col-md-8 col-sm-8">
       {{ getLastAction(activity) }}
 </div>

AngularJS:

$scope.getLastAction= function (activity) {
    if (activity) {
        let desc= activity.Desc;
        let first= activity.First;

        let res=  desc+ '<br>' + first;
        return res;
    }
}

我试图放<br>和\ n,但是都没有。

1 个答案:

答案 0 :(得分:0)

使用ng-bind-html指令。

<div class="col-md-8 col-sm-8">
       <span class="test" ng-bind-html="test"></span>
</div>

JS

$scope.getLastAction= function (activity) {
    if (activity) {
        let desc= activity.Desc;
        let first= activity.First;

        let res=  desc+ '<br>' + first;
        $scope.test = res;
    }
}