20 lines
621 B
TypeScript
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);
|
||
|
}
|
||
|
}
|