Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IViewDecoratorOptions<T>

This type allows various settings for the view. It's optional and all members are optional. A standard view with the view model being build by own code and properties are instantiated, it's usually not required. However, if the model is generated by a tool, such as NSwag, and the initialization steps are not part of the default ctor call, the viewmodel must be "enhanced". There are two options:

  1. If the viewmodel has a constructor that requires parameters, use the @param ctor to deliver the parameters.
  2. If the viewmodel has an initialization function ofr nothing at all, use @param factory to create a factory. You get the current object and apply your changes.

The thirs option is regarding handlers. Handlers define, which property is bound in which way. In case you need a special treatment for Date values, create a Handler through implementing the IBindingHandler interface. It has two features: Listen for events and change value if the bound object changes. You can skip the listener part to have an unidirectional binding. Internally there are three pre-defined handlers:

  1. innerText: An unidirectional binder that writes text in any HTMLElement
  2. value: A binder that handles any kind of {@link IHTMLInputElement} ; this is bi-directional
  3. checkbox: Handles a value by accepting a boolean value and supports the checked property instead of value.

Type parameters

  • T

    The view model

Hierarchy

  • IViewDecoratorOptions

Index

Properties

Properties

Optional ctor

ctor: Partial<T>

An optional object used to create an instance. This overrides the view model's default constructor.

Optional factory

factory: (model: T) => void

If the ctor option is not flexible enough and you need a very constructed object, this is the right way to setup.

In the following example the factory sets just one property to a distinct value (a pre-fill).

example```
customelement('app-forms-demo')
viewmodel(contactmodel,

{ factory: m => m.email = 'bla@fasel.com', handler: { 'value': new ValueBindingHandler() } }) export class FormsDemoComponent extends BaseComponent implements IModel {

model: ModelBinder;

// omitted for brevity }


If you access the model (without any further code required) like this: `this.model.scope.email` the value is already filled in.
An even more complex setup is possible providing a definition like this:

@example```
 factory: (m: ContactModel) => {
   m.email = 'bla@fasel.com';
   m.name = 'Test Name';
 }
param

Placeholder for the model type

typeparam

The view model type

Type declaration

    • (model: T): void
    • Parameters

      • model: T

      Returns void

Optional handler

handler: {}

An optional list of handlers, that handle custom binding operations. Assign the name used in n-bind and an instance of the binder class.

@ViewModel<Model>(Model, { handler: { 'special': new SpecialBinder() }})

In this scenario, the class SpecialBinder must implement IBindingHandler. Any bindings that apply to 'special' are now being re-routed through this custom binder code (exclusively, bypassing the default binders).

Type declaration

Generated using TypeDoc