javascript - 如何在文本之间添加水平线
问题描述
现在晚上,我的后端有两个文本响应,我想知道如何才能使看起来像下面的设计。我不确定这是否可能,但任何建议或帮助将不胜感激。
如果有两个或多个广播,我只想自动添加一条水平线来分隔文本,而不是像现在这样显示在同一行(图片)。
<mat-card class="alert" *ngIf="broadcastNotifications?.length">
<mat-card-title *ngFor="let broadcast of broadcastNotifications">
<p style="font-size: 15px; color: black; margin-top: 25px;">{{broadcast.message}}</p>
</mat-card-title>
</mat-card>
this.notificationService.getNotification().subscribe((response: any) => {
if(response && response.length){
const alerts = response.filter(el => el.notificationType === 2);
this.broadcastNotifications = response.filter(el => el.notificationType === 1);
if(alerts.length){
this.dialog.open(ReleaseDialogComponent, {
data : {notifications: alerts}
});
}
}
})
它现在的样子与我想做的事情。
[![在此处输入图像描述][1]][1]
解决方案
您可以将<mat-divider>
用于此目的。将 for 循环移动到 anng-container
并添加<mat-divider>
所有不是最后一个元素的元素。
<mat-card class="alert" *ngIf="broadcastNotifications?.length">
<ng-container *ngFor="let broadcast of broadcastNotifications; let i = index">
<mat-card-title>
<p style="font-size: 15px; color: black; margin-top: 25px;">{{broadcast.message}}</p>
</mat-card-title>
<mat-divider *ngIf="broadcastNotifications.length - 1 !== i"></mat-divider>
</ng-container>
</mat-card>
示例可以在这里找到
推荐阅读
- javascript - 当我不点击项目时,为什么 JavaScript 会执行“点击”事件?
- java - 从文件上传弹性搜索中的数据
- javascript - 使用对象参数将 javascript 代码绑定到 android 代码
- hyperledger-fabric - Hyperledger 结构是否每个对等方多次广播事件?
- graphql - 如何在 GraphQL 对象中组合多个字段
- java - SOAP Web 服务优于 REST 的实时实际情况?
- entity-framework-core-2.1 - Entity Framework Core 2.1 System.Data.SqlClient.SqlException (0x80131904):类型标志不是定义的系统类型
- python-3.x - 我可以将文本文件转换为 python 字典吗?
- reactjs - React JS 条件渲染,如 Eval
- php - 我如何使用ajax php过滤复选框