File

src/app/component/chat-widget/chat-widget-container.ts

Extends

BasePortalOutlet

Implements

OnDestroy

Metadata

changeDetection ChangeDetectionStrategy.OnPush
host {
}
moduleId module.id
selector stbui-chat-widget-container
styleUrls chat-widget-container.scss
templateUrl chat-widget-container.html

Index

Properties
Methods

Constructor

constructor(elementRef: ElementRef, changeDetectorRef: ChangeDetectorRef)
Parameters :
Name Type Optional
elementRef ElementRef No
changeDetectorRef ChangeDetectorRef No

Methods

_onAnimationDone
_onAnimationDone(event: AnimationEvent)
Parameters :
Name Type Optional
event AnimationEvent No
Returns : void
_onAnimationStart
_onAnimationStart(event: AnimationEvent)
Parameters :
Name Type Optional
event AnimationEvent No
Returns : void
attachComponentPortal
attachComponentPortal(portal: ComponentPortal)
Type parameters :
  • T
Parameters :
Name Type Optional
portal ComponentPortal<T> No
Returns : ComponentRef<T>
attachTemplatePortal
attachTemplatePortal(portal: TemplatePortal)
Type parameters :
  • C
Parameters :
Name Type Optional
portal TemplatePortal<C> No
Returns : EmbeddedViewRef<C>
enter
enter()
Returns : void
exit
exit()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void

Properties

_animationState
Type : "void" | "visible" | "hidden"
Default value : 'void'
_animationStateChanged
Default value : new EventEmitter<AnimationEvent>()
Private _destroyed
Type : boolean
_portalOutlet
Type : CdkPortalOutlet
Decorators :
@ViewChild(CdkPortalOutlet, {static: false})
import {
  Component,
  ComponentRef,
  EmbeddedViewRef,
  ViewChild,
  ElementRef,
  ChangeDetectorRef,
  OnDestroy,
  ChangeDetectionStrategy,
  EventEmitter
} from '@angular/core';
import {AnimationEvent} from '@angular/animations';
import {
  BasePortalOutlet,
  ComponentPortal,
  TemplatePortal,
  CdkPortalOutlet
} from '@angular/cdk/portal';
import { ChatWidgetAnimations } from './chat-widget.animation';

@Component({
  moduleId: module.id,
  selector: 'stbui-chat-widget-container',
  templateUrl: 'chat-widget-container.html',
  styleUrls: ['chat-widget-container.scss'],
  animations: [ChatWidgetAnimations.chatWidgetState],
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: {
    class: 'stbbui-chat-widget-container',
    '[@state]': '_animationState',
    '(@state.start)': '_onAnimationStart($event)',
    '(@state.done)': '_onAnimationDone($event)'
  }
})
export class ChatWidgetContainer extends BasePortalOutlet implements OnDestroy {
  @ViewChild(CdkPortalOutlet, { static: false }) _portalOutlet: CdkPortalOutlet;
  _animationStateChanged = new EventEmitter<AnimationEvent>();

  _animationState: 'void' | 'visible' | 'hidden' = 'void';
  private _destroyed: boolean;

  constructor(
    private elementRef: ElementRef,
    private changeDetectorRef: ChangeDetectorRef
  ) {
    super();
  }

  ngOnDestroy() {
    this._destroyed = true;
  }

  attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
    return this._portalOutlet.attachComponentPortal(portal);
  }

  attachTemplatePortal<C>(portal: TemplatePortal<C>): EmbeddedViewRef<C> {
    return this._portalOutlet.attachTemplatePortal(portal);
  }

  enter(): void {
    if (!this._destroyed) {
      this._animationState = 'visible';
      this.changeDetectorRef.detectChanges();
    }
  }

  exit(): void {
    if (!this._destroyed) {
      this._animationState = 'hidden';
      this.changeDetectorRef.markForCheck();
    }
  }

  _onAnimationStart(event: AnimationEvent) {
    this._animationStateChanged.emit(event);
  }
  _onAnimationDone(event: AnimationEvent) {
    this._animationStateChanged.emit(event);
  }
}
<ng-template cdkPortalOutlet></ng-template>

chat-widget-container.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""