File

feature-libs/asm/components/asm-toggle-ui/asm-toggle-ui.component.ts

Implements

OnInit OnDestroy

Metadata

selector cx-asm-toggle-ui
templateUrl ./asm-toggle-ui.component.html

Index

Properties
Methods

Constructor

constructor(asmService: AsmService)
Parameters :
Name Type Optional
asmService AsmService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
toggleUi
toggleUi()
Returns : void

Properties

isCollapsed
Type : boolean
Protected subscription
Default value : new Subscription()
import { Component, OnDestroy, OnInit } from '@angular/core';
import { AsmService, AsmUi } from '@spartacus/asm/core';
import { Subscription } from 'rxjs';

@Component({
  selector: 'cx-asm-toggle-ui',
  templateUrl: './asm-toggle-ui.component.html',
})
export class AsmToggleUiComponent implements OnInit, OnDestroy {
  protected subscription = new Subscription();
  isCollapsed: boolean;

  constructor(protected asmService: AsmService) {}

  ngOnInit(): void {
    this.subscription.add(
      this.asmService.getAsmUiState().subscribe((uiState: AsmUi) => {
        this.isCollapsed =
          uiState.collapsed === undefined ? false : uiState.collapsed;
      })
    );
  }

  toggleUi(): void {
    this.asmService.updateAsmUiState({ collapsed: !this.isCollapsed });
  }

  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
}
<a class="toggleUi" (click)="toggleUi()">
  <span [ngClass]="!isCollapsed ? 'collapseIcon' : 'expandIcon'"></span>
  <span *ngIf="!isCollapsed" class="label">
    {{ 'asm.toggleUi.collapse' | cxTranslate }}
  </span>
  <span *ngIf="isCollapsed" class="label">
    {{ 'asm.toggleUi.expand' | cxTranslate }}
  </span>
</a>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""