导航/路由回组件时未触发ngOnInit

时间:2019-11-03 11:49:25

标签: angular angular-routing ngoninit

我想从服务中检索数据并将其分配给组件以进行查看和更新​​。它起作用了,但是每当我导航到其他路线并回来时,它就消失了,一切都不确定。我需要针对这种情况的解决方案。

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 };
        })
     );

0 个答案:

没有答案