#Page not working when subscription is added in the Onint

7 messages · Page 1 of 1 (latest)

lunar juniper
#
ngOnInit() {
    console.log('school list');
    this.sub = this.adminService.adminControllerGetSchools().subscribe((res) => {
      this.schoolList.set(res);
      return res;
    })
  }

  ngOnDestroy() {
    this.sub.unsubscribe();
  }

the page kept going back to the former route
but if I remove the subscription the page routes properly

{
    path: 'dashboard',
    loadComponent: () => import('./dashboard/dashboard.component').then(m => m.DashboardComponent)
  },
  {
    path: 'schools',
    component: SchoolsComponent,
    children: [
      {
        path: '',
        component: SchoolListComponent
      },
      {
        path: 'inter-school',
        loadComponent: () => import('./schools/inter-school/inter-school.component').then(m => m.InterSchoolComponent)
      },
      {
        path: 'intra-school',
        loadComponent: () => import('./schools/intra-school/intra-school.component').then(m => m.IntraSchoolComponent)
      },
      {
        path: 'school-detail/:id',
        loadComponent: () => import('./schools/school-detail/school-detail.component').then(m => m.SchoolDetailComponent)
      }
    ]
  },

the page goes back to dashboard

civic stirrup
#

Not related to your issue, but you don't have to return inside the subscribe method

#

What does adminControllerGetSchools do?

lunar juniper
#

it fetch data from the server

#
adminControllerGetSchools<TData = GetSchoolResponse[]>(
     options?: HttpClientOptions
  ): Observable<TData>  {
    return this.http.get<TData>(
      `http://localhost:3000/api/admin/get-schools`,options
    );
  }
pulsar cypress
#

Check if you have an error in your browser dev tools (network panel). Add an error callback when you subscribe to see if there is an error.

lunar juniper