@WidgetComponent
File
Implements
Metadata
selector |
nm-html-content |
styleUrls |
html-content.component.scss |
templateUrl |
./html-content.component.html |
Index
Widget inputs
|
|
|
Widget outputs
|
|
Properties
|
|
Methods
|
|
Constructor
constructor(translateService: TranslateService, sanitizer: DomSanitizer)
|
|
Parameters :
Name |
Type |
Optional |
translateService |
TranslateService
|
no
|
sanitizer |
DomSanitizer
|
no
|
|
Methods
Protected
configureWidget
|
configureWidget(configuration: WidgetConfig)
|
Decorators : WidgetConfigure
|
|
|
Public
ngOnDestroy
|
ngOnDestroy()
|
|
|
Public
_id
|
_id:
|
Decorators : WidgetId
|
|
Public
contentInput
|
contentInput: Subject<any>
|
Type : Subject<any>
|
Default value : new ReplaySubject<any>(1)
|
Decorators : WidgetInput
|
|
|
Public
translateService
|
translateService: TranslateService
|
Type : TranslateService
|
|
Private
unsubscribe
|
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
|
import { takeUntil } from "rxjs/operators";
import { Component, OnDestroy } from "@angular/core";
import { DomSanitizer, SafeHtml } from "@angular/platform-browser";
import { ReplaySubject, Subject } from "rxjs";
import { getOrDefault, WidgetConfig } from "../widget.configuration";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetId,
WidgetInput,
} from "../widget.metadata";
import { NgUnsubscribe } from "../../ng-unsubscribe";
import { TranslateService } from "@ngx-translate/core";
import { BaseConfiguration } from "../widgetframe";
export interface HtmlContentConfiguration extends BaseConfiguration {
/**
* HTML code to be shown in the component
*/
content?: string;
}
@WidgetComponent("nm-html-content")
@Component({
selector: "nm-html-content",
templateUrl: "./html-content.component.html",
styleUrls: ["./html-content.component.scss"],
})
export class HtmlContentWidgetComponent implements OnDestroy {
@WidgetId()
public _id;
@WidgetConfiguration()
public configuration: WidgetConfig<HtmlContentConfiguration>;
/**
* Sets HTML content.
*/
@WidgetInput("contentInput")
public contentInput: Subject<any> = new ReplaySubject<any>(1);
public withHeader: boolean;
public content: SafeHtml = "";
private unsubscribe = NgUnsubscribe.create();
constructor(
public translateService: TranslateService,
private sanitizer: DomSanitizer
) {}
@WidgetConfigure()
protected configureWidget(
configuration: WidgetConfig<HtmlContentConfiguration>
) {
this.withHeader = getOrDefault(
configuration.configuration.withHeader,
true
);
if (configuration.configuration["content"]) {
this.content = this.sanitizer.bypassSecurityTrustHtml(
configuration.configuration["content"]
);
}
this.contentInput.pipe(takeUntil(this.unsubscribe)).subscribe((content) => {
this.content = this.sanitizer.bypassSecurityTrustHtml(content);
});
}
public ngOnDestroy(): void {
this.unsubscribe.destroy();
}
}
<nm-widgetframe
[header]="configuration.configuration['header']"
[toolbarInvisible]="!withHeader"
>
<div slot="title" class="nm-widgetframe__title">
{{ configuration.configuration["title"] | translate }}
<nm-help-icon
*ngIf="configuration.configuration['infoText']"
style="position: absolute; display: inline; right: 50px; z-index: 666"
[info-text]="configuration.configuration['infoText'] | translate"
[info-title]="configuration.configuration['title'] | translate"
[info-placement]="'left'"
[wiki-link]="configuration.configuration['wikiLink']"
></nm-help-icon>
</div>
<div slot="content" class="nm-widgetframe__content">
<div [innerHtml]="content"></div>
</div>
</nm-widgetframe>
Legend
Html element with directive