Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Polymer data-binding

I want to make two way data binding between Polymer and Angular, for this I am using Angu-poly library.

Here is a link to an example which is working, while passing strings via name and age attributes: working.

<x-kid bind-polymer ng-repeat="kid in kids" angupoly="{name:'kid.name', age:'kid.age'}">
</x-kid>

But when I try to make it with passing an object via kid attribute, it seems that something goes wrong, here is the link: not working.

<x-kid bind-polymer angupoly="{kid:'kid'}">
</x-kid>

What should I do to make it work?

Update:
Also tried it with this library and it didn't work. the code will look like this:

<x-kid bind-polymer kid={{kid}}>
</x-kid>

Big Update:
Here I made some progress tweaking the "angular-bind-polymer" library. For now I am able to bind objects from outside polymer into polymer, here is the updated plunker. The problem now is to do this in the other direction.
Note: I am getting some exception from angular side, take a look maybe you can help to solve it. I think we are very close :).

like image 566
vlio20 Avatar asked Jun 21 '14 09:06

vlio20


People also ask

What is data binding in polymer?

A data binding connects data from a custom element (the host element) to a property or attribute of an element in its local DOM (the child or target element). The host element data can be a property or sub-property represented by a data path, or data generated based on one or more paths.

How does Angular do data binding?

Data binding in Angular works by synchronizing the data in the components with the UI so that it reflects the current value of the data. To achieve the synchronization of the View and the Model, Angular uses change detection.

Which of the following syntax is used for data binding?

The [(ngModel)] syntax is the recommended way of two-way data binding. The ngModel directive with [] syntax is used for one-way data binding. [ngModel] binds a value to a property to UI control.


5 Answers

Here is an updated example http://plnkr.co/w1icAU

With Polymer 1.0 two way binding is much simpler and also able to bind objects not just string values.

Here is the main part

<x-kid ng-repeat="kid in ::kids" angupoly="{name:'kid.name', age:'kid.age'}"></x-kid>
like image 132
Matjaz Lipus Avatar answered Sep 30 '22 12:09

Matjaz Lipus


I think it is because of some kind of reference.

How should I explain, just like you work with object in scope in data binding. when you update the object to a new object, the UI will not update with new object values.

like image 25
Mavlarn Avatar answered Oct 01 '22 12:10

Mavlarn


It looks that Material Design is THE answer, excerpt:

Our goal is to deliver a lean, lightweight set of AngularJS-native UI elements that implement the material design system for use in Angular SPAs.

like image 23
Jean Davy Avatar answered Oct 02 '22 12:10

Jean Davy


Maybe you could find clues from this blog even if its aim is for dart:

Angular and Polymer Data Binding, Together!

like image 44
memedidou Avatar answered Oct 01 '22 12:10

memedidou


Also take a look at ng-polymer, this project may help give you some insight

like image 24
dan Avatar answered Oct 04 '22 12:10

dan