src/app/shared/widgets/label/label.component.ts
Properties |
|
fromInputStream |
fromInputStream:
|
Type : boolean
|
Optional |
A flag to represent the source of label text from either a localized property key or an input stream |
text |
text:
|
Type : string
|
Optional |
A localized property key that used in fetching the suitable label text based on ui locale |
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"];
}
}
}