Skip to content
npm

API service reference ​

NgxViewBuilderApiService is the one service your application talks to. Inject it anywhere, in a page component, a resolver, a service of your own, and use it to read and change the view on screen, react to what happens in it, and plug your own functions, validators, elements and icons in.

ts
import { inject } from '@angular/core';
import { NgxViewBuilderApiService } from '@ngxviewbuilder/runtime';

export class ClientPage {
  private readonly api = inject(NgxViewBuilderApiService);

  async save(): Promise<void> {
    const result = await this.api.validateData();
    if (result.isValid) {
      await this.clients.save(this.api.getData());
    }
  }
}

An application that hosts the builder imports the same service from @ngxviewbuilder/designer. It is the same class.

How a call reaches the view ​

You always inject the root service. What it talks to depends on what is on screen:

On screenCalls about the view (values, structure, elements, validation) go toRegistrations (functions, validators, elements, icons, theme) go to
<ngx-view-builder-runtime>that runtime viewthe root and every runtime view, now and later
several runtime viewsthe one created lastthe root and every runtime view
<nvb-scope>the scopethe root and every scope
<ngx-view-builder-designer>the view being edited (the builder owns it)the root, the builder and its Preview
nothing yetthe root itselfthe root; views created later pick them up

Two things follow from that table. You can register everything at startup, before any view exists, and every view gets it. And you never need a reference to a particular runtime, because the root forwards. When several views render at once, every event still reaches the root and carries elementName and elementDataPath, which is how you tell them apart.

Waiting for a view

Values and elements exist once the view has rendered. Subscribe to onAfterRender, or call the API from a button or an event handler, rather than straight from your constructor.

Reading this reference ​

Each page groups the methods of one area. Every method shows its signature, what it does, an example, and what it returns. Types are written in TypeScript; IStructure is the view JSON described in Structure JSON.

PageWhat it covers
Structure & settingsRead, replace and patch the view definition and its settings
Data & valuesForm data, single values, server errors, the dirty flag
ElementsFinding elements, reading and writing their properties, the element handle, rows of repeaters, element defaults
Validation & lifecycleValidating the view or any structure, toasts, render and completion notifications
Data sources & variablesReloading sources, host sources, websocket authorization, runtime variables and external context
Language & themeLanguage, locale, translations, UI dictionaries, theme modes, tokens and custom CSS
ExtensionsExpression functions, validator types, custom elements and properties, icons, table cells
Builder, templates & tablesTemplate library, element library, table settings and filters, builder tabs

Events have their own page: Events reference.

Every method at a glance ​

AreaMethods
StructuregetStructure · getStructureModel · setStructure · updateStructure · notifyStructureChanged · captureStructureSource · clearCapturedStructureSource
SettingsgetSettings · getSetting · setSetting · patchSettings · updateSettings · replaceSettings
DatagetData · setData · setElementsData · setValue · setElementValue · getElementValue · clearValue · clearValues · clearElementValue · resetElementValue · clearData · isDirty · markPristine · setElementErrors · clearElementErrors · getElementErrors
Element lookupgetElement · getElementModel · getElementLookup · getElementByDataPath · getElementBySchemaPath · getRenderedElements · getElementName and friends · describeElement
DOMgetElementDom · getElementDomById · getElementDomByTestId · queryRenderDom · queryRenderDomAll · getRenderRoot · registerRenderRoot
PropertiesgetElementProperty · setElementProperty · setElementProperties · removeElementProperty · removeElementProperties · resetElementProperty · resetElementProperties · updateElement · refreshElement
Element handleelement · getElementApi · rows · columns · cells
Element defaultssetElementTypeDefault · setElementTypeDefaults · setElementDefaults · defaults · getElementDefaults · clearElementDefaults · getElementTypeBuiltInDefaults
ValidationvalidateData · showToast · notifyValidationResult · notifyComplete · notifySaveRequested
Lifecyclerender notifications · notifyTabChanged · notifyCurrentPageChanged · notifyDialogClosed · element interaction notifications
Data sourcesreloadDataSource · reloadElementDataSource · reloadElementsByDataSource · setDefaultDataSources · setDataSourceTypeSettings · getDataSourceTypeSettings · setWebsocketAuthorizer
VariablessetRuntimeVariableContext · getRuntimeVariableContext · clearRuntimeVariableContext · setRuntimeVariableDefinitions · getRuntimeVariableDefinitions · configureRuntimeVariables
LanguagegetLanguage · setLanguage · resolveHostLanguage · applyHostLanguage · startLanguageSync · setApplicationLocale · getApplicationLocale · setLocale · setContentTranslations · setUiDictionaries · setUiTranslations · translateUi · setPropertyHints · setPropertyTypeHints
ThemesetThemeMode · getThemeMode · setTheme · setCustomTheme · getCustomTheme · setCssVariables · getCssVariables · setCustomCss · getCustomCss · setCustomCssUrls · getCustomCssUrls
ExtensionsregisterExtensions · registerExtensionsAsync · expression functions · validator types · getRegisteredValidatorTypes · clearRegisteredValidatorTypes · custom elements · registerElementGroup · element properties · SVG icons · table cell types · getTableHeaderCenterExtensions
TemplatesgetTemplates · loadTemplates · saveTemplate · deleteTemplate · setTemplateActionMap · registerTemplateActionDataSource
Element libraryloadSidebarGroups · saveSidebarGroup · deleteSidebarGroup
TablessetTableSettings · getTableSettings · setTableFilters · getTableFilters · setTableSavedFilters · getTableSavedFilters · request* methods
BuilderswitchToTab · requestTabChange · isBuilderAttached · getBuilderAdapter · attachBuilderAdapter · setAiAssistantConfig · getAiAssistantConfig