Returns the scope's proxy instance, so changes to properties are pushed to binders.
Set the object (model) the component is bound to. This is a proxy that monitors changes and renders the bound elements using binders.
An object instance that is monitored for binding
Use this to subsribe to model changes. If it's bound to an input element this will fire for all assigned bindings, which more convenient than listing for events directly. I's safe to assign the subscriber in the contructor of a component.
The name of the property; must be a member of the view model.
A callback being executed when the value changes.
Returns the Binder for a component. Each component has it's very own binder instance.
The component this instance is assigned to
Initialize a binder for the current form. This is global and you can bind only one form at a time. Add custom binders to bind non-trivial properties. Usually, you shoudn't call this directly. It's public because it's being called from the @ViewModel decorator. The decorators adds a hidden property to store the binder instance directly in the component.
The web component this binder is currently attached to.
Handler identifier, used in forms in n-bind="prop: Value"
.
Generated using TypeDoc
The modelbinder serves two purposes: First, the bi-directional data binding. Second, the converting of validation decorators into validation instructions.
The bi-directional binding is uni-directional if the element doesn't support user input. That means, you can bind any element. The binding is based on a {@link Proxy} class and requires ES2015 natively.
The binding two a model requires the decorator {@link Viewmodel}. Here you define the type for binding.
@ViewModel(UserModel) export class Component extends BaseComponent<{}> implements IModel<UserModel>
At any part of your component you can now access a real object that is being synhcronized:
model: ModelBinder<UserModel>;
In the form you define the binding with the property
n-bind
like this:<input type="text" n-bind="value: Name" ... />
The property has two parts:
value
).The @nyaf/forms library provides few binder functions, that consists of a name (the property name) and a binder logic. For example, the * ValueBindingHandler has the name "value" and reads a value from {@link HTMLInputElement} 's
value
property. It also contains an event listener, that supervises theinput
event. Binders for text may not have an event listener and hence bind just uni-directional.If you need specific binders for custom elements, just create one by implementing the IBindingHandler interface.
class MyHandler implements IBindingHandler { // your code here }
This definition must be added to the local modelbinder instance. The decorator {@link @ViewModel} creates a property
model
, that provides an instance of {@link ModelBinder,} initialized and bound to the current component. In the component, it's recommended to do this in the Lifecycle.Load step, you can add your custom handler:@ViewModel(UserModel, { handlers: { 'custom': new CustomHandler() } })
The} interface. That's for typing, the actual value is created at
runtime from the decorator code.
model
property is enforced by the {@link IModelIn the form you can now bind to your custom property of your custom web component.
<app-myinput n-bind="custom: Name" ... />