javascript - Readonly component in angular doesn't show line breaks
问题描述
I am working on a Angular with C# application. And I have some read-only components for showing saved data from the database. For example I put in a Textarea component the following text:
hello
there
hello
so this is with spaces. Then it will correctly saved in the database. Because when I choose for Edit the text will been show correct. But after I save the text and I choose for details the text. Then the alinea's are not correctly been showing. Because the alinea's are been removed.
I tried with <pre></pre>
but then the text will be formatted correctly but it breaks the layout.
So if I do this:
<pre>
<afw-readonly [resources]="resources" fieldResourceKeyPrefix="beschrijving"
[fieldValue]="learningPathDetails.description" [enableHtml]="false"
[readMoreCharLimit]="300"
></afw-readonly>
</pre>
then the formatting will be shown correctly. But the layout is broken.
So how to correct this? Thank you
解决方案
<pre>
维护换行非常有用,但它会破坏布局。问题是你可以通过使用 CSS 来做同样的事情。
var someText = `This is some text with some new lines.
Line 1
Line 2
Line 3. Kewl.`;
$("pre").text(someText);
$(".simulate-pre").text(someText);
$(".no-pre").text(someText);
.margins * {
margin: 5px 0;
}
.real-pre {
border: 1px solid red;
}
.simulate-pre {
border: 1px solid purple;
white-space: pre-line;
}
.no-pre {
border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="margins">
<pre class="real-pre"></pre>
<div class="simulate-pre"></div>
<div class="no-pre"></div>
</div>
推荐阅读
- symfony - 如何切换 Symfony 的 php-translation/symfony-bundle EditInPlace
- spring - 休眠、事务和数据大小
- c# - EventLog security.evtx 垃圾邮件是如何发生的?
- google-chrome-extension - 从 Chrome 扩展覆盖 CanvasRenderingContext2D
- javascript - JS 上的 Selenium 获得 Promise Pending
- mysql - 比较两个表格中的分数,并显示最近不同的分数
- android - 如何通过android profiler测量android应用程序的冷启动时间
- python - 在 sqlite 中使用 max 时光标未填充
- c++ - MSVC C++ ADL 错误?
- spring - 如何在 AWS ElasticBeanstalk 和 Nginx 上使用 OAuth2 的 Spring Boot 应用程序上强制 SSL?