File

core/dynamic-component/dynamic-component.component.ts

Description

C8y dynamic component.

register component in HOOK in module:

Example :
 import { hookComponent } from '@c8y/ngx-components';

@NgModule({
 ...,
 providers: [
   hookComponent({
     id: 'test-component',
     label: 'My test component',
     description: 'this is test component',
     component: TestComponent
   })
 ...
 ]

Showing dynamic component:

Example :
<c8y-dynamic-component [componentId]="'test-component'" [config]="config"></c8y-dynamic-component>

Implements

OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs

Inputs

componentId
Type : string

The ID of the registered component. It needs to be a component that is hooked with the HOOK_COMPONENTS extension hook.

config

The configuration to pass.

executeResolvers
Type : boolean
Default value : false

If set to true, it will execute the components resolvers before initializing the component. Defaults to false.

mode
Type : "config" | "component"
Default value : 'component'

DynamicComponents can have two modes, an edit (config) and an view (component) mode. By default it is shown in the component mode.

notFoundError
Type : boolean
Default value : true

Disable this to hide the error that is shown if the component was not found.

Outputs

updateWidgetClasses
Type : EventEmitter

Allows to set additional classes for widget styling.

Methods

callLifeCycleHooks
callLifeCycleHooks()

Calls the dynamic component life cycle hook. Currently only supporting onBeforeSave, a hook which is called before a config component is saved.

Returns : any
emitConfigChange
emitConfigChange(newConfigValues)

If an outside component changes the configuration, this function triggers ngOnChange on the dynamic component.

Parameters :
Name Optional Description
newConfigValues No

The new configuration value.

Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void

Properties

componentInstance
Type : DynamicComponent
dynamicComponentErrorStrategy
Default value : DynamicComponentErrorStrategy
errorStrategy
Type : DynamicComponentErrorStrategy
<ng-template #host></ng-template>

<div class="alert alert-warning m-8" role="alert" *ngIf="error && notFoundError">
  <strong class="message">
    {{
      'This widget cannot be rendered because the current application does not support the following component:'
        | translate
    }}
    {{ componentId }}.
  </strong>
  <p class="text-muted m-t-8">
    <button class="btn btn-clean" (click)="expandErrorDetails = !expandErrorDetails">
      <i c8yIcon="chevron-down"></i>
      <span *ngIf="!expandErrorDetails" translate>Show details</span>
      <span *ngIf="expandErrorDetails" translate>Hide details</span>
    </button>
  </p>
  <div [collapse]="!expandErrorDetails" [isAnimated]="true">
    <pre>
      {{ error }}
    </pre>
  </div>
</div>

<div
  class="overlay-center-vertically d-flex d-col a-i-stretch j-c-start p-16 p-r-24 p-l-24"
  *ngIf="
    errorStrategy === dynamicComponentErrorStrategy.OVERLAY_ERROR &&
      componentInstance?.alerts?.anyAlertExists$ | async
  "
>
  <c8y-dynamic-component-alerts [alerts]="componentInstance.alerts"></c8y-dynamic-component-alerts>
</div>

results matching ""

    No results matching ""