File

feature-libs/cart/saved-cart/components/details/saved-cart-details-action/saved-cart-details-action.component.ts

Implements

OnDestroy

Metadata

selector cx-saved-cart-details-action
templateUrl ./saved-cart-details-action.component.html

Index

Properties
Methods

Constructor

constructor(savedCartDetailsService: SavedCartDetailsService, vcr: ViewContainerRef, launchDialogService: LaunchDialogService)
Parameters :
Name Type Optional
savedCartDetailsService SavedCartDetailsService No
vcr ViewContainerRef No
launchDialogService LaunchDialogService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
openDialog
openDialog(cart: Cart, type: SavedCartFormType)
Parameters :
Name Type Optional
cart Cart No
type SavedCartFormType No
Returns : void

Properties

element
Type : ElementRef
Decorators :
@ViewChild('element')
savedCart$
Type : Observable<Cart | undefined>
Default value : this.savedCartDetailsService.getCartDetails()
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
Component
Html element with directive

result-matching ""

    No results matching ""