File

feature-libs/asm/components/customer-emulation/customer-emulation.component.ts

Implements

OnInit OnDestroy

Metadata

selector cx-customer-emulation
templateUrl ./customer-emulation.component.html

Index

Properties
Methods

Constructor

constructor(asmComponentService: AsmComponentService, userService: UserService)
Parameters :
Name Type Optional
asmComponentService AsmComponentService No
userService UserService No

Methods

logoutCustomer
logoutCustomer()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

customer
Type : User
isCustomerEmulationSessionInProgress$
Type : Observable<boolean>
Protected subscription
Default value : new Subscription()
import { Component, OnDestroy, OnInit } from '@angular/core';
import { User, UserService } from '@spartacus/core';
import { Observable, Subscription } from 'rxjs';
import { AsmComponentService } from '../services/asm-component.service';

@Component({
  selector: 'cx-customer-emulation',
  templateUrl: './customer-emulation.component.html',
})
export class CustomerEmulationComponent implements OnInit, OnDestroy {
  customer: User;
  isCustomerEmulationSessionInProgress$: Observable<boolean>;
  protected subscription = new Subscription();

  constructor(
    protected asmComponentService: AsmComponentService,
    protected userService: UserService
  ) {}

  ngOnInit() {
    this.subscription.add(
      this.userService.get().subscribe((user) => {
        if (user) this.customer = user;
      })
    );
    this.isCustomerEmulationSessionInProgress$ =
      this.asmComponentService.isCustomerEmulationSessionInProgress();
  }

  logoutCustomer() {
    this.asmComponentService.logoutCustomer();
  }

  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
}
<ng-container *ngIf="isCustomerEmulationSessionInProgress$ | async">
  <input
    formcontrolname="customer"
    type="text"
    disabled="true"
    placeholder="{{ customer?.name }}, {{ customer?.uid }}"
  />
  <button (click)="logoutCustomer()">
    {{ 'asm.endSession' | cxTranslate }}
  </button>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""