Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

<router-outlet></router-outlet> empty after calling Resolve<any> #667

Open
farrukh-whitecoat opened this issue Feb 19, 2019 · 1 comment

Comments

@farrukh-whitecoat
Copy link

farrukh-whitecoat commented Feb 19, 2019

router-outlet empty after calling Resolve in AppResolver class. loaded data show on page when i see as a page view source. html does now render in router-outlet

@farrukh-whitecoat
Copy link
Author

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { FetchDataComponent } from './fetch-data/fetch-data.component';
import { HomeComponent } from './home/home.component';
import { AppResolver } from './app.resolver';

const routes: Routes = [
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'fetch-data', component: FetchDataComponent, resolve: { cres: AppResolver } }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

component:
constructor(private route: ActivatedRoute, private httpClient: HttpClient, @Inject('BASE_URL') baseUrl, private practiceService: PracticeService) {

this.route.data.map(data => data.cres).subscribe((practice: Practice) => {
  console.log(practice);
  this.initPracticeDetails(practice);
  //this.forecasts = res;
 });

}

app resolver

import { Injectable, Inject } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/delay';
import { HttpClient } from '@angular/common/http';
import { Practice } from './interfaces/Practice';
import { map } from 'rxjs-compat/operator/map';
import { PracticeService } from './services/practice.service';

@Injectable()
export class AppResolver implements Resolve {

url: string;
constructor(private http: HttpClient, @Inject('BASE_URL') baseUrl, private practiceService: PracticeService) {
this.url = baseUrl;
}

resolve(route: ActivatedRouteSnapshot, rstate: RouterStateSnapshot): Observable | Promise | any {

return this.http.get(`api/practice/945076/956`);

}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant