我想从服务中检索数据并将其分配给组件以进行查看和更新。它起作用了,但是每当我导航到其他路线并回来时,它就消失了,一切都不确定。我需要针对这种情况的解决方案。
TodoComponent
ngOnInit(){
this.abv = this.memberData.memberData$.subscribe(res => {
this.todos = res.todos.todo;
this.done = res.todos.done;
})
}
路由模块
const routes: Routes = [
{path:'', component:MemberComponent, children:[
{path:'profile', component: ProfileComponent},
{path:'todo', component: TodoComponent}
]}
];
服务
this.memberData$ = this.memberRef.snapshotChanges()
.pipe(
map(action => {
const data = action.payload.data();
const id = action.payload.id;
return { id, ...data };
})
);