Giter Site home page Giter Site logo

rise-vision / angular-bind-polymer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eee-c/angular-bind-polymer

0.0 21.0 0.0 107 KB

Angular directive for *double* variable binding of Polymer attributes.

License: MIT License

JavaScript 80.79% HTML 19.21%

angular-bind-polymer's Introduction

angular-bind-polymer

Angular directive for double variable binding of Polymer attributes.

N.B. This will not work with raw paper/core elements because they do not publish their attributes. See note below on Polymer Usage for details.

Installation

Use bower to install:

$ bower install angular-bind-polymer

Usage

Script order is important. The web components platform (polyfills) need to be loaded first, followed by the Angular library and then this library (angular-bind-polymer):

<script src="bower_components/platform/platform.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="angular_bind_polymer.js"></script>

The Angular module needs to be inititialized before the Polymer elements are imported otherwise Polymer will overwrite the attributes before angular-bind-polymer has a chance to process them.

Add eee-c.angularBindPolymer as dependency for your Angular application:

var PizzaStoreApp = angular.module('pizzaStoreApp', [
  'eee-c.angularBindPolymer'
]);

The final piece of setup is to import the Polymer elements:

<link rel="import" href="test/x-double.html">

To bind values from Polymer elements, apply the bind-polymer directive:

<x-pizza bind-polymer state="{{pizzaState}}"></x-pizza>
<pre ng-bind="pizzaState"></pre>

Changes from the <x-pizza> custom element will now update the pizzaState variable in local scope.

Note: changes in Angular's scope are already bound. That is, changes to pizzaState will update the <x-pizza> custom element without this or any other modules. This directive is soley used to watch for changes in custom elements for the purposes of updating a bound variable in Angular's scope.

Support in Polymer

This will only work if the Polymer element publishes and reflects attributes. That is, it is insufficient to declare attributes:

<!-- THIS WON'T WORK!!! -->
<polymer-element name="x-double" attributes="in out">
  <template><!-- ... --></template>
  <script>
    // ...
  </script>
</polymer-element>

To mark the out attribute as reflectable, declare it as such with the publish property:

<polymer-element name="x-double" attributes="in out">
  <template><!-- ... --></template>
  <script>
    Polymer("x-double", {
      publish: {
        out: {value: 0, reflect: true}
      },
      // ...
    });
  </script>
</polymer-element>

Unfortunately, core and paper elements tend not to reflect attributes at this time. This means that this directive will not work with them. Hopefully this will change in the near future.

Contributors

Much thanks to everyone that has helped with suggestions. In particular, thanks to the following for code improvements:

angular-bind-polymer's People

Contributors

0x-r4bbit avatar eee-c avatar heavysixer avatar rodrigopavezi avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.