Angular Resolve Guard - TekTutorialsHub
Fri Feb 17 2023 10:04:46 GMT+0000 (Coordinated Universal Time)
Saved by
@mtommasi
@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} }
content_copyCOPY
https://www.tektutorialshub.com/angular/angular-resolve-guard/
Comments