barker/bookie/src/app/product/product-resolver.service.ts
2019-06-15 23:09:43 +05:30

20 lines
621 B
TypeScript

import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {ProductService} from './product.service';
import {Product} from '../core/product';
import {Observable} from 'rxjs/internal/Observable';
@Injectable({
providedIn: 'root'
})
export class ProductResolver implements Resolve<Product> {
constructor(private ser: ProductService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Product> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}
}