Directives And Filters

Provided classes, directives, filters, services

For component or serivce development Servoy has a public api that can be installed with "npm i @servoy/public" for a service or component package. And then needs to be imported in the angular @NgModule declartion:

import { ServoyPublicModule } from '@servoy/public';

imports: [
      ServoyPublicModule,
      ]

This will provide various Angular Directives, Filters and Services that a component or service can use to integrate into the servoy product or use it as generic helpers.

For component development the most important one is the ServoyBaseComponent because every component needs to extend that one to get the default interface/behavior for integrating into the NGClient.

Provided Services/Classes

ServoyPlublicService

This service has various function to interact with the Servoy Environment.

it can be imported by:

import { ServoyPublicService } from '@servoy/public';

constructor(private servoyService: ServoyPublicService) {}

See the api below:

ServoyBaseComponent

Every component needs to extends this component

By default this BaseComponent has 3 inputs:

that are injected and exposed.

It also has function that exposes the getNativeElement() (the html tag where #element attribute is in). Also getNativeChild() can by overwritten if you have a nested attribute that is more the real element. By default getNativeChild() returns the same thing as getNativeElement()

ServoyApi

The ServoyApi class is the api that interacts with the servoy system (calling the server).

See the api below:

FormattingService

This is a service that can perform various data -> string formatting or string -> data unformatting on various types, based on the format object that Servoy provides through the format property

The api:

MaskFormat

This is a helper class in the formatting area. The formatting service will also use this internally when the format is a configured to be a mask.

LoggerFactory

This service can be used by components and services to create a Logger for a specific class ang log to certain levels.

LoggerService

This is returned by the getLogger() call on the factory. It has the various log functions on the different log levels. Besides that it has a helper method to build a message if that message is a lot of string concatting and should only be build if the message is really logged

The api:

The LogLevel is enum:

TooltipService

The tooltip service is a service that can also be used standalone if you can't use the directive) The directive uses this service under the hood.

The api:

Provided Directives

svyFormat

This directive takes care of the formatting to the data that is given, it is a ControlValueAccessor in combination of the NgModel It expects that it gets a Format object assigned that a component gets to the format

In the component typescript code:

the tempplate:

It has also a attribute/property by itself "findmode" so the formatter knows when it is findmode and shouldn't try to format at all.

svyStartEdit

This directive calls startEdit on focus through the clientside servoyApi object which a component gets by default and is exposed by the ServoyBaseComponent which all components should extend. The value that it needs is the property where the edit is for, as an example: [svyStartEdit]="'dataProviderID'", so this is the string of the property where it should work on, not the value (see the '' inside the "") and it needs a reference to the actual component through the hostComponent property: [hostComponent]="this"

the template:

svyDecimalKeyConverter

This directives monitors the key presses to see if the decimal key is press and inserts the correct , or . for the locale the user is in. In expect to get assigned the format so it can check it is a number format.

the template:

svyTooltip

A directive that takes care of the (html) tooltips that must be set on the component, it is a wrapper around the tooltipservice so you don't have to do the event bindings your self.

the template:

svyTabFix

This directive should be used by components that are showing popups like the typeahead when the component needs to close the popup when the tab key is pressed The component needs to implement IPopupSupportComponent

the template:

the component ts:

svyUpload

This directive is a wrapper around ServoyPlublicService.showFileOpenDialog() and ServoyPlublicService.generateUploadUrl() To let the user on click on this component opens a file open dialog and then upload the selected file to the server for the given form and component. Currently the property is hardcoded as 'dataProviderID'. so it will upload to "[formname].[componentname].dataProviderID"

the template:

sabloTabseq

This directive should get as a value the tabSequence property of the component

See Sablotabsequence for more information what a component can do with it (like being a container itself for multiply tabsequences)

Provided Filters

Besides these directives there are also some angular filters:

formatFilter

This is a wrapper around the FormattingService that you can use in labels, so none editable components, instead of using the FormatDirective in components that support edit of data.

The given value of the dataproviderID property will go through the format filter that gets as the argument the format property to format the data.

htmlFilter:

only returns html that is inside tags so filters the rest outside of it.

After the format the htmlFilter will then strip the body and the parents tags if the html string had those.

trustAsHtml

trustAsHtml:servoyApi.trustAsHtml() if the give boolean is true, then the input will not be sanitized but use as is.

After the formatting of the value the trustAsHtml will mark the give value as trusted (if the argument of isTrustedHTML() is true) so then it will not be sanitized or the sanitizer of Angular will sanitize it.

The servoyApi can be asked if it should be trusted (set by the system or a ui property on the component). But it can also be that the component has a property that supports this:

emptyValue

This filter inserts a '\u00A0' for a '' so it is a none breaking space in the html.

"

notNullOrEmpty

This filter filters all null or empty values from an array so that you only loop over actual values in a *for loop in a template:

Last updated

Was this helpful?