File

projects/rebirth-ng/src/lib/ellipsis/ellipsis.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
exportAs ellipsis
selector re-ellipsis
styleUrls ellipsis.component.scss
templateUrl ./ellipsis.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(rebirthNGConfig: RebirthNGConfig, documentRef: DocumentRef)
Parameters :
Name Type Optional
rebirthNGConfig RebirthNGConfig no
documentRef DocumentRef no

Inputs

html

Default value: false

max

Type: number

placement

Type: "top" | "bottom" | "left" | "right"

text

Type: string

Methods

Private ellipsis
ellipsis()
Returns : void
Private unCodeHtml
unCodeHtml(text: string)
Parameters :
Name Type Optional
text string no
Returns : string

Properties

ellipsisText
ellipsisText: string
Type : string
Default value : ''
fullText
fullText: string
Type : string
Default value : ''
length
length: number
Type : number

Accessors

max
setmax(length: number)
Parameters :
Name Type Optional
length number no
Returns : void
text
settext(text: string)
Parameters :
Name Type Optional
text string no
Returns : void
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { RebirthNGConfig } from '../rebirth-ng.config';
import { DocumentRef } from '../window-ref/document-ref.service';

@Component({
  selector: 're-ellipsis',
  templateUrl: './ellipsis.component.html',
  styleUrls: ['./ellipsis.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  exportAs: 'ellipsis'
})
export class EllipsisComponent {
  length: number;
  fullText = '';
  ellipsisText = '';
  @Input() placement: 'top' | 'bottom' | 'left' | 'right';
  @Input() html = false;

  constructor(rebirthNGConfig: RebirthNGConfig, private documentRef: DocumentRef) {
    this.length = rebirthNGConfig.ellipsis.length;
    this.placement = <any>rebirthNGConfig.ellipsis.placement;
  }

  @Input()
  set max(length: number) {
    this.length = length;
    this.ellipsis();
  }

  @Input()
  set text(text: string) {
    this.fullText = text || '';
    this.ellipsis();
  }

  private ellipsis() {
    const text = this.html ? this.unCodeHtml(this.fullText) : this.fullText;
    this.ellipsisText = text.length > this.length ? text.substr(0, this.length) : '';
  }

  private unCodeHtml(text: string) {
    const $div = this.documentRef.createElement('div');
    $div.innerHTML = text;
    text = $div.innerText;
    return text;
  }
}
<span *ngIf="ellipsisText" [reTooltip]="fullText" [placement]="placement">{{ellipsisText}}...</span>
<span *ngIf="!html && !ellipsisText">{{fullText}}</span>
<span *ngIf="html && !ellipsisText" [innerHTML]="fullText"></span>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""