@Injectable()
export class ProductListResolverService implements Resolve<Product>{
constructor(private productService:ProductService ) {
}
resolve(route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<any> {
console.log("ProductListResover is called");
return this.productService.getProducts();
}
}
// the component that uses the resolver:
ngOnInit() {
this.products=this.route.snapshot.data['products'];
}
//the routing module
{ path: 'product', component: ProductComponent,
resolve: {products: ProductListResolveService, , data:SomeOtherResolverService} }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter