html - 添加新消息时聊天应用程序不滚动
问题描述
我使用 Ionic 4 和 Firebase 创建了一个聊天应用程序。但是,它没有滚动,因此我无法添加更多消息。
这是html:
<ion-content>
<ion-grid>
<ion-row *ngFor="let message of messages.message">
<ion-col size="9" *ngIf="myItinerary.userId !== message.userId" class="message other-user">
<span>{{message.content}}</span>
<div class="time" text-right><br>
{{message.createdAt | date: 'short'}}</div>
</ion-col>
<ion-col offset="3" size="9" *ngIf="myItinerary.userId === message.userId" class="message me">
<span>{{message.content}}</span>
<div class="time" text-right><br>
{{message.createdAt | date: 'short'}}</div>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
<ion-footer>
<ion-toolbar light="light">
<ion-row align-items-center no-padding>
<ion-col size="10">
<textarea autosize maxRows="3" [(ngModel)]="newMsg" class="message-input"></textarea>
</ion-col>
<ion-col size="2">
<ion-button expand="block" fill="clear" color="primary" [disabled]="newMsg === ''" class="msg-btn"
(click)="sendMessage()">
<ion-icon name="ios-send" slot="icon-only"></ion-icon>
</ion-button>
</ion-col>
</ion-row>
</ion-toolbar>
</ion-footer>
这是我找到的示例,它可以工作...我可以添加消息,但它不会滚动。我没有收到错误
我正在根据海报的建议添加 .css ......它也不起作用,但我可能没有正确执行它。
.message{
padding: 10px;
border-radius: 10px;
margin-bottom: 4px;
white-space: pre-wrap
}
.other-user{
background: var(--ion-color-tertiary);
color: #fff;
}
.me{
background: var(--ion-color-secondary);
color: #fff;
}
.time{
color: #dfdfdf;
float: right;
font-size: small;
}
.message-input {
width: 100%;
border: 1px solid var(--ion-color-medium);
border-radius: 10px;
background: #fff;
resize: none;
padding-left: 10px;
padding-right: 10px;
}
.msg-btn {
--padding-start: 0.5em;
--padding-end: 0.5em;
}
.style{
display: "flex";
flex-wrap: "wrap";
overflow: "auto";
}
每添加 css
解决方案
我通过用 ion-list 替换 ion-grid 来解决这个问题。
<ion-content>
<ion-list lines="none">
<ion-item *ngFor="let message of messages.message">
<div size="9" *ngIf="myItinerary.userId !== message.userId" class="message other-user">
<span>{{message.content}}</span>
<div class="time" text-right><br>
{{message.createdAt | date: 'short'}}</div>
</div>
<div offset="3" size="9" *ngIf="myItinerary.userId === message.userId" class="message me" slot="end">
<span>{{message.content}}</span>
<div class="time" text-right><br>
{{message.createdAt | date: 'short'}}</div>
</div>
</ion-item>
</ion-list>
</ion-content>
推荐阅读
- c - 为什么我的 getline() 没有读取 C 中标准输入的第一行?
- git - 如何使用 git rebase --empty=drop
- batch-file - 有什么技巧可以让我的 CMD 游戏看起来更好吗?
- sql - ASP.NET 字符串值作为查询命令
- php - Woocommerce 删除退款订单的下载权限,使用 wc 核心功能中的查询触发器
- r - 将Long Form数据转换为R中的三维数组
- python - 在python中返回一个字符串并且只得到一个空数组
- mysql - 使用 SQL 识别和标记记录时间
- python - Solver (baron) 返回非零返回码 (1)
- .net - 搜索 Microsoft.Extensions.Caching.Memory.MemoryCache 的源代码