File

src/lib/timeago.directive.ts

Metadata

Index

Methods
Inputs
Accessors

Inputs

date
Type : string | number | Date

The Date to display. An actual Date object or something that can be fed to new Date.

live
Type : boolean

If the directive should update itself over time

Methods

setContent
setContent(node: any, content: string)
Parameters :
Name Type Optional
node any No
content string No
Returns : void

Accessors

date
setdate(date: string | number | Date)

The Date to display. An actual Date object or something that can be fed to new Date.

Parameters :
Name Type Optional
date string | number | Date No
Returns : void
live
setlive(live: boolean)

If the directive should update itself over time

Parameters :
Name Type Optional
live boolean No
Returns : void
import {
  Directive,
  ElementRef,
  inject,
  Input,
} from '@angular/core';
import {
  coerceBoolean,
  IsDefinedAndNotNull,
} from '@rxap/utilities';
import { TimeagoFormatter } from './timeago.formatter';

@Directive({
  selector: '[rxapTimeago]',
  exportAs: 'rxapTimeago',
  standalone: true,
})
export class TimeagoDirective {

  private readonly elementRef = inject(ElementRef);

  /** The Date to display. An actual Date object or something that can be fed to new Date. */
  @Input()
  set date(date: string | number | Date) {
    this.setContent(this.elementRef.nativeElement, TimeagoFormatter(date));
  }

  private _live = true;

  /** If the directive should update itself over time */
  @Input()
  set live(live: boolean) {
    this._live = coerceBoolean(live);
  }

  setContent(node: any, content: string) {
    if (IsDefinedAndNotNull(node.textContent)) {
      node.textContent = content;
    } else {
      node.data = content;
    }
  }

}

results matching ""

    No results matching ""