【发布时间】:2017-08-28 18:36:33
【问题描述】:
请帮忙,我有一个消息服务,它从数据库中获取我的消息并将它们显示在用户个人资料页面上。创建或删除消息时,只有刷新浏览器才能看到更改。
在我应用过滤器以按 Id 排序之前,页面会动态更新,为什么过滤器会取消绑定我的消息数组?
配置文件组件:
export class ProfileComponent implements OnInit {
user: User;
userId: any;
messages: any;
constructor(private authService: AuthService, private messageService: MessageService) {}
ngOnInit() {
this.authService.getUser().subscribe(
(user: User) => {
this.user = user;
this.userId = user.userId;
}
);
this.messageService.getMessages()
.subscribe(
(messages: Message[]) => {
this.messages = messages.filter(x => x.userId == this.userId);
//this.messages = messages; //this works perfect, but shows all users messages
}
);
}
}
【问题讨论】:
-
我真的希望有人能帮助我..我不知道为什么我的视图不会自行更新,因为它订阅了我正在添加和删除的相同消息
标签: node.js mongodb angular express mean-stack