Binder
#
Basic Binder UsageBinder syncs the data between an HTMLElement and an Object.
Example:
Enter the following code in app-component.html
:
Now enter this in app-component.js
:
As the <input>
and div
have the same data
attribute, they are synced. Any changes made in the input field will be reflected in the div section. Furthermore, the content of the <div>
section can be retrieved and used anywhere by using this.data.name
in the component's JS file.
#
Binder PluginsBinder Plugin allows you to write your own custom plugins.
Before creating your own plugin, read below workflow of binder to have a perfect understanding of how it works.
#
The Basic workflow of binderBinder has basically getter and setter method.
- Getter method is always used to listen for user input in any form of HTMLElement and push those data to a respective object.
- Setter method is always used to set the data of object towards any HTMLElement. If a value is set to an object key, those values will reflect the HTMLElement.
#
How to write custom binder plugins?You can write getter and setter methods in '< component >-config.js'.
Getter and Setter example:
#
Binder prioritiesThere is a priority to executing all plugins. Plugin which matches at first will executes and the rest won't.
For example,
#
Exclude pluginsIt is possible exclude default plugins and write your own.
#
Default Plugins#
How to exclude default plugins?Import default plugins and add it in 'excludePlugins' array.