File
Implements
Metadata
| selector |
cx-customer-emulation |
| templateUrl |
./customer-emulation.component.html |
Methods
|
logoutCustomer
|
logoutCustomer()
|
|
|
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
|
|
|
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 with directive