我可以从数据库中将数据读取到我的角度应用程序,但我只是在文本中得到静态\n而不是新行。我知道我应该将所有\n出现的情况转换为<br />但我未能做到这一点,即使使用echo nl2br;
//extract from my php file
if($result = mysqli_query($con, $sql))
{
$animals = [];
$cr = 0;
while($row = mysqli_fetch_assoc($result))
{
$animals[$cr]['animal'] = $row['animal'];
$animals[$cr]['t1'] = $row['title1'];
$animals[$cr]['p1'] = $row['paragraph1'];
$cr++;
}
echo nl2br($animals);
echo json_encode($animals);
下面是我的角度文件
//extract from my animals.component.html file
<div class="container" *ngFor="let animal of this.animals">
{{animal.t1}}
{{animal.p1}}
{{animal.t2}}
</div>
但是,我在网页上的输出(来自animal.t1)与数据库条目的文本完全相同:
Animals \n are \n fun \n .
我尝试了许多不同的方法,但似乎无法将\n's 转换为<br>. 有人对此有什么建议吗?
侃侃尔雅
慕后森