Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2-way data binding in native web components

I've been reading up on web components and am pretty intrigued by the nascent spec. Does anyone know if there is any support for 2-way data binding in the DOM, without having to use Polymer? An example would be appreciated.

like image 389
aamiri Avatar asked Nov 10 '14 14:11

aamiri


People also ask

Is it possible to bind data in Web Components?

This in itself is a valid point, but nevertheless data binding is easy to achieve for Web Components as I will demonstrate in this article. Data binding was first made popular by frameworks like Angular, Backbone and Ember and is now more or less the de facto way of writing views.

What is two-way data binding in angular?

One of the major features of angular is two-way data binding in components. But, Angular also focuses on splitting the work into smaller components. Now there can be situations where you have split your task into the smaller components but then you come up with another requirement that you also want two-way data binding between your components.

How does two-way data binding work with Sizer components?

For two-way data binding to work, the @ Output () property must use the pattern, inputChange, where input is the name of the @ Input () property. For example, if the @ Input () property is size, the @ Output () property must be sizeChange. The following sizerComponent has a size value property and a sizeChange event.

What is two-way binding?

Two-way binding gives components in your application a way to share data. Use two-way binding to listen for events and update values simultaneously between parent and child components. See the live example / download example for a working example containing the code snippets in this guide.


Video Answer


1 Answers

Object.observe is a potential new way to do databinding in javascript. This feature is scheduled for Ecmascript 7(javascript), but some browsers currently support it, check here. Also check out this html5rocks article on object.observe

like image 67
dan Avatar answered Nov 13 '22 00:11

dan