File

feature-libs/organization/administration/components/shared/item-exists.directive.ts

Implements

OnInit OnDestroy

Metadata

Selector [cxOrgItemExists]

Index

Properties
Methods

Constructor

constructor(itemService: ItemService<T>, messageService: MessageService)
Parameters :
Name Type Optional
itemService ItemService<T> No
messageService MessageService No

Methods

Protected handleErrorMessage
handleErrorMessage()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Protected subscription
import { Directive, OnDestroy, OnInit } from '@angular/core';
import { GlobalMessageType } from '@spartacus/core';
import { filter } from 'rxjs/operators';
import { ItemService } from './item.service';
import { MessageService } from './message/services/message.service';
import { BaseItem } from './organization.model';

@Directive({
  selector: '[cxOrgItemExists]',
})
export class ItemExistsDirective<T = BaseItem> implements OnInit, OnDestroy {
  protected subscription;

  constructor(
    protected itemService: ItemService<T>,
    protected messageService: MessageService
  ) {}

  ngOnInit() {
    this.subscription = this.itemService.error$
      .pipe(filter((error) => error))
      .subscribe(() => this.handleErrorMessage());
  }

  protected handleErrorMessage() {
    this.messageService.add({
      message: {
        key: 'organization.notification.notExist',
      },
      type: GlobalMessageType.MSG_TYPE_ERROR,
    });
  }

  ngOnDestroy() {
    this.subscription?.unsubscribe();
  }
}

result-matching ""

    No results matching ""