nm-label
src/app/shared/widgets/label/label.component.ts
The "nm-label" component supports the configuration of label text from two sources (localized property key or text input stream).
changeDetection | ChangeDetectionStrategy.OnPush |
selector | nm-label |
styleUrls | label.component.scss |
templateUrl | ./label.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(translateService: TranslateService)
|
||||||
Parameters :
|
Protected configureWidget | ||||||
configureWidget(configuration: WidgetConfig
|
||||||
Decorators : WidgetConfigure
|
||||||
Parameters :
Returns :
void
|
Public _id |
_id:
|
Decorators : WidgetId
|
Public configuration |
configuration:
|
Type : WidgetConfig<LabelConfiguration>
|
Decorators : WidgetConfiguration
|
Public text |
text:
|
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:
|
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>