docs: refactor code in get-product
docregion of getting-started
docs example (#40197)
This commit slightly refactors the code in the `get-product` docregion of the `getting-started` docs example to make it easier to follow. PR Close #40197
This commit is contained in:
parent
1d78d4d774
commit
d08828339b
@ -24,11 +24,11 @@ export class ProductDetailsComponent implements OnInit {
|
|||||||
// #docregion get-product
|
// #docregion get-product
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// First get the product id from the current route.
|
// First get the product id from the current route.
|
||||||
const productIdFromRoute = this.route.snapshot.paramMap.get('productId');
|
const routeParams = this.route.snapshot.paramMap;
|
||||||
|
const productIdFromRoute = Number(routeParams.get('productId'));
|
||||||
|
|
||||||
// Find the product that correspond with the id provided in route.
|
// Find the product that correspond with the id provided in route.
|
||||||
this.product = products.find(product => {
|
this.product = products.find(product => product.id === productIdFromRoute);
|
||||||
return product.id === Number(productIdFromRoute);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// #enddocregion get-product
|
// #enddocregion get-product
|
||||||
// #docregion product-prop
|
// #docregion product-prop
|
||||||
|
@ -30,11 +30,11 @@ export class ProductDetailsComponent implements OnInit {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// #enddocregion props-methods
|
// #enddocregion props-methods
|
||||||
// First get the product id from the current route.
|
// First get the product id from the current route.
|
||||||
const productIdFromRoute = this.route.snapshot.paramMap.get('productId');
|
const routeParams = this.route.snapshot.paramMap;
|
||||||
|
const productIdFromRoute = Number(routeParams.get('productId'));
|
||||||
|
|
||||||
// Find the product that correspond with the id provided in route.
|
// Find the product that correspond with the id provided in route.
|
||||||
this.product = products.find(product => {
|
this.product = products.find(product => product.id === productIdFromRoute);
|
||||||
return product.id === Number(productIdFromRoute);
|
|
||||||
});
|
|
||||||
// #docregion props-methods
|
// #docregion props-methods
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user