@WidgetComponent

nm-label

File

src/app/shared/widgets/label/label.component.ts

Description

The "nm-label" component supports the configuration of label text from two sources (localized property key or text input stream).

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector nm-label
styleUrls label.component.scss
templateUrl ./label.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(translateService: TranslateService)
Parameters :
Name Type Optional
translateService TranslateService no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig<LabelConfiguration> no
Returns : void

Properties

Public _id
_id:
Decorators : WidgetId
Public configuration
configuration: WidgetConfig<LabelConfiguration>
Type : WidgetConfig<LabelConfiguration>
Decorators : WidgetConfiguration
Public text
text: string
Type : string
Default value : ""
Public textFromStream
textFromStream:
Default value : new ReplaySubject<any>(2)
Decorators : WidgetInput

Trigger updating of label text from an input stream

Public translateService
translateService: TranslateService
Type : TranslateService
import { Component, ChangeDetectionStrategy } from "@angular/core";
import { ReplaySubject } from "rxjs";
import { WidgetConfig } from "../widget.configuration";
import {
  WidgetComponent,
  WidgetId,
  WidgetConfiguration,
  WidgetConfigure,
  WidgetInput,
} from "../widget.metadata";
import { TranslateService } from "@ngx-translate/core";

export interface LabelConfiguration {
  /**
   * A localized property key that used in fetching the suitable label text based on ui locale
   */
  text?: string;

  /**
   * A flag to represent the source of label text from either a localized property key or an input stream
   */
  fromInputStream?: boolean;
}

/**
 * The "nm-label" component supports the configuration of label text from two sources
 * (localized property key or text input stream).
 */
@WidgetComponent("nm-label")
@Component({
  selector: "nm-label",
  templateUrl: "./label.component.html",
  styleUrls: ["./label.component.scss"],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LabelWidgetComponent {
  @WidgetId()
  public _id;

  @WidgetConfiguration()
  public configuration: WidgetConfig<LabelConfiguration>;

  /**
   * Trigger updating of label text from an input stream
   */
  @WidgetInput("textFromStream")
  public textFromStream = new ReplaySubject<any>(2);

  public text: string = "";

  constructor(public translateService: TranslateService) {}

  @WidgetConfigure()
  protected configureWidget(configuration: WidgetConfig<LabelConfiguration>) {
    if (configuration.configuration["fromInputStream"]) {
    } else {
      this.text = configuration.configuration["text"];
    }
  }
}
<span> {{ text | translate }} {{ textFromStream | async }} </span>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""