File
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-configure-product |
| templateUrl |
./configure-product.component.html |
|
nonConfigurable
|
Type : Product
|
Default value : { configurable: false }
|
|
|
|
product$
|
Type : Observable<Product>
|
Default value : (this.productListItemContext
? this.productListItemContext.product$
: this.currentProductService
? this.currentProductService.getProduct(
ConfiguratorProductScope.CONFIGURATOR
)
: of(null)
).pipe(
//needed because also currentProductService might return null
map((product) => (product ? product : this.nonConfigurable))
)
|
|
|
import { ChangeDetectionStrategy, Component, Optional } from '@angular/core';
import { Product } from '@spartacus/core';
import {
CurrentProductService,
ProductListItemContext,
} from '@spartacus/storefront';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { CommonConfigurator } from '../../core/model/common-configurator.model';
import { ConfiguratorProductScope } from '../../core/model/configurator-product-scope';
@Component({
selector: 'cx-configure-product',
templateUrl: './configure-product.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ConfigureProductComponent {
nonConfigurable: Product = { configurable: false };
product$: Observable<Product> = (this.productListItemContext
? this.productListItemContext.product$
: this.currentProductService
? this.currentProductService.getProduct(
ConfiguratorProductScope.CONFIGURATOR
)
: of(null)
).pipe(
//needed because also currentProductService might return null
map((product) => (product ? product : this.nonConfigurable))
);
ownerTypeProduct: CommonConfigurator.OwnerType =
CommonConfigurator.OwnerType.PRODUCT;
constructor(
@Optional() protected productListItemContext: ProductListItemContext, // when on PLP
@Optional() protected currentProductService: CurrentProductService // when on PDP
) {}
}
<ng-container *ngIf="product$ | async as product">
<ng-container *ngIf="product.configurable">
<a
[routerLink]="
{
cxRoute: 'configure' + product.configuratorType,
params: {
ownerType: ownerTypeProduct,
entityKey: product.code
}
} | cxUrl
"
class="btn btn-primary btn-block"
cxAutoFocus
>{{ 'configurator.header.toconfig' | cxTranslate }}</a
>
</ng-container>
</ng-container>
Legend
Html element with directive