角-在HTML上创建新行 [英] angular - create a new line on HTML

查看:109
本文介绍了角-在HTML上创建新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题(希望如此).我有一个返回结果为字符串的服务.格式如下:

I have a simple question (I hope this). I have a service that return a string as result. The format is something like this:

"Test1:关联已被接受.\ nTest2:关联已被接受.\ n"

" Test1: the association has been accepted.\nTest2: the association has been accepted.\n" "

在客户端(我使用的是Angular 1.5.x),我将该字符串放入对象中(例如变量$ scope.alert.message).之后,我想以模式打印该字符串.我的html是:

On the client side (I'm using Angular 1.5.x) I put that string into a object (say the variable $scope.alert.message). After that I want to print that string in a modal. My html is:

<script type="text/ng-template" id="infoTemplate.html">
    <div class="modal-header left" ng-class="['div-' + alert.type, closeable ? 'alert-dismissible' : null]">
        <h3 class="modal-title" id="modal-title">Info</h3>
    </div>
    <div class="modal-body" id="modal-body">
        <img class="imm-info" ng-class="['imm-' + alert.type, closeable ? 'alert-dismissible' : null]" />
        <p class="col-sm-10 col-sm-offset-2">{{alert.message}}</p><button class="col-sm-3 col-sm-offset-5 btn " ng-class="['button-' + alert.type, closeable ? 'alert-dismissible' : null]" ng-click="cancel()">OK</button>
    </div>
</script>

您可以看到"{{alert.message}}".我的问题是我的消息不显示"字符"\ n".因此,它不会创建多于一行.此处的示例:

You can see the '{{alert.message}}'. My problem is that my message "doesn't display" the character '\n'. So it doesn't create more than one line. An example here:

示例

推荐答案

尝试使用HTML:

<pre>{{ alert.message }}</pre>

已经在此处回答了

<pre>包装器将以\ n作为文本打印文本

The < pre > wrapper will print text with \n as text

这篇关于角-在HTML上创建新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆