我有一系列来自后端的数据,我的要求如下:
"from_user_name"
为Anonymus
,我必须隐藏内容。所以任何人都可以帮助我解决这两个问题。
HTML:
<ul>
<li *ngFor="let message of activeMessages" (click)="showMessage(message)" [class.activeShow]="message.id == message_id">
<span>{{message.updated_at | date:'dd.MM.yyyy'}}</span>
<img style="width: 40px;" [src]="message.from_user_image || '../assets/images/msg.png'"/>
<p style="padding-top: 16px;display: inline;">{{message.from_user_name}}</p>
<p style="padding-top: 10px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"><b>{{message.text}}</b></p>
</li>
</ul>
TS:
loadMessages() {
this.service
.getMessages()
.subscribe(
data => {
this.messagesdata = data;
this.activeMessages = data.filter(msg => msg.active == true);
this.closedMessages = data.filter(msg => msg.active == false);
if (this.activeMessages.length > 0) {
if(!this.message_show) {
var test = this.message_show = this.activeMessages[0];
this.message = true;
this.message_id = this.activeMessages[0].id;
}
console.log(this.activeMessages);
}
},error => {});
}
答案 0 :(得分:1)
这种行为应该从后端过滤掉,但在其他情况下,这是正确的代码:
loadMessages() {
this.service
.getMessages()
.subscribe(
data => this.activeMessages = data.filter(msg => msg.active && msg.from_user_name !== 'Anonymus' && msg.messages.length > 0)
}