File

src/app/core/entity/entity-field-view/entity-field-view.component.ts

Description

Generic component to display one entity property field's viewComponent.

Dynamically extends field details from entity schema and loads the relevant, specific EditComponent implementation.

For editComponent form field, see EntityFieldEditComponent.

Metadata

Index

Properties
Inputs

Inputs

entity
Type : E
field
Type : ColumnConfig

field id or full config

showLabel
Type : "inline" | "above" | "none"
Default value : "none"

Properties

Readonly _field
Type : unknown
Default value : computed<FormFieldConfig | undefined>(() => { const entity = this.entity(); const field = this.field(); if (!entity?.getConstructor()) return undefined; return this.entityFormService.extendFormFieldConfig( field, entity.getConstructor(), ); })

full field config extended from schema

import {
  Component,
  computed,
  inject,
  input,
  ChangeDetectionStrategy,
} from "@angular/core";
import {
  ColumnConfig,
  FormFieldConfig,
} from "../../common-components/entity-form/FormConfig";
import { EntityFormService } from "../../common-components/entity-form/entity-form.service";
import { DynamicComponentDirective } from "../../config/dynamic-components/dynamic-component.directive";
import { Entity } from "../model/entity";

/**
 * Generic component to display one entity property field's viewComponent.
 *
 * Dynamically extends field details from entity schema and
 * loads the relevant, specific EditComponent implementation.
 *
 * For editComponent form field, see EntityFieldEditComponent.
 */
@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-entity-field-view",
  templateUrl: "./entity-field-view.component.html",
  styleUrls: ["./entity-field-view.component.scss"],
  imports: [DynamicComponentDirective],
})
export class EntityFieldViewComponent<E extends Entity = Entity> {
  private entityFormService = inject(EntityFormService);

  entity = input<E>();

  /** field id or full config */
  field = input<ColumnConfig>();

  showLabel = input<"inline" | "above" | "none">("none");

  /** full field config extended from schema */
  readonly _field = computed<FormFieldConfig | undefined>(() => {
    const entity = this.entity();
    const field = this.field();
    if (!entity?.getConstructor()) return undefined;
    return this.entityFormService.extendFormFieldConfig(
      field,
      entity.getConstructor(),
    );
  });
}
@if (_field()) {
  <div>
    @if (showLabel() === "above") {
      <div class="label">
        {{ _field().label }}
      </div>
    } @else if (showLabel() === "inline") {
      <span>{{ _field().label }}:&nbsp;</span>
    }
    @if (_field().viewComponent) {
      <ng-container
        [appDynamicComponent]="{
          component: _field().viewComponent,
          config: {
            value: entity()[_field().id],
            id: _field().id,
            entity: entity(),
            formFieldConfig: _field(),
          },
        }"
      ></ng-container>
    }
  </div>
}

./entity-field-view.component.scss

@use "variables/colors";

.label {
  font-size: 12px;
  color: colors.$muted;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""