File
Implements
Metadata
| selector |
cx-saved-cart-details-action |
| templateUrl |
./saved-cart-details-action.component.html |
Methods
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
|
|
|
element
|
Type : ElementRef
|
Decorators :
@ViewChild('element')
|
|
|
|
savedCartFormType
|
Default value : SavedCartFormType
|
|
|
|
Private
subscription
|
Default value : new Subscription()
|
|
|
import {
Component,
ElementRef,
OnDestroy,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { SavedCartFormType } from '@spartacus/cart/saved-cart/root';
import { Cart } from '@spartacus/core';
import { LaunchDialogService, LAUNCH_CALLER } from '@spartacus/storefront';
import { Observable, Subscription } from 'rxjs';
import { take } from 'rxjs/operators';
import { SavedCartDetailsService } from '../saved-cart-details.service';
@Component({
selector: 'cx-saved-cart-details-action',
templateUrl: './saved-cart-details-action.component.html',
})
export class SavedCartDetailsActionComponent implements OnDestroy {
private subscription = new Subscription();
savedCartFormType = SavedCartFormType;
@ViewChild('element') element: ElementRef;
savedCart$: Observable<Cart | undefined> =
this.savedCartDetailsService.getCartDetails();
constructor(
protected savedCartDetailsService: SavedCartDetailsService,
protected vcr: ViewContainerRef,
protected launchDialogService: LaunchDialogService
) {}
openDialog(cart: Cart, type: SavedCartFormType): void {
const dialog = this.launchDialogService.openDialog(
LAUNCH_CALLER.SAVED_CART,
this.element,
this.vcr,
{ cart, layoutOption: type }
);
if (dialog) {
this.subscription.add(dialog.pipe(take(1)).subscribe());
}
}
ngOnDestroy(): void {
this.subscription?.unsubscribe();
}
}
<ng-container *ngIf="savedCart$ | async as cart">
<div class="cx-saved-cart-restore-btns row">
<div class="col-xs-12 col-md-5 col-lg-4">
<button
#element
class="btn btn-block btn-action"
(click)="openDialog(cart, savedCartFormType.DELETE)"
>
{{ 'savedCartDetails.deleteSavedCart' | cxTranslate }}
</button>
</div>
<div class="col-xs-12 col-md-5 col-lg-4">
<button
#element
class="btn btn-block btn-primary"
(click)="openDialog(cart, savedCartFormType.RESTORE)"
>
{{ 'savedCartList.makeCartActive' | cxTranslate }}
</button>
</div>
</div>
</ng-container>
Legend
Html element with directive