├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── bower.json
├── circle.yml
├── docs
├── api.adoc
├── best-practices.adoc
├── ng-cli-webpack.adoc
├── overview.adoc
├── tutorial-index.adoc
└── tutorial
│ ├── creating-project.adoc
│ ├── dependencies.adoc
│ ├── hero-editor.adoc
│ ├── img
│ ├── app-layout.png
│ ├── hero-details.png
│ ├── heroes-list-default.png
│ └── heroes-list.png
│ ├── introduction.adoc
│ ├── layout.adoc
│ ├── list-heroes.adoc
│ ├── polymer.adoc
│ └── wrap-up.adoc
├── index.spec.ts
├── index.ts
├── karma.conf.js
├── package.json
├── src
├── polymer-element.spec.ts
├── polymer-element.ts
├── polymer-module.spec.ts
├── polymer-module.ts
├── renderer
│ ├── polymer-renderer.spec.ts
│ ├── polymer-renderer.ts
│ └── shared-custom-styles-host.ts
└── test-element.html
├── system.config.js
├── tsconfig.json
└── tslint.json
/.gitignore:
--------------------------------------------------------------------------------
1 | *.js
2 | !karma.conf.js
3 | !system.config.js
4 | *.d.ts
5 |
6 | # Created by https://www.gitignore.io/api/node,bower,typings
7 |
8 | ### Node ###
9 | # Logs
10 | logs
11 | *.log
12 | npm-debug.log*
13 |
14 | # Runtime data
15 | pids
16 | *.pid
17 | *.seed
18 |
19 | # Directory for instrumented libs generated by jscoverage/JSCover
20 | lib-cov
21 |
22 | # Coverage directory used by tools like istanbul
23 | coverage
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # node-waf configuration
32 | .lock-wscript
33 |
34 | # Compiled binary addons (http://nodejs.org/api/addons.html)
35 | build/Release
36 |
37 | # Dependency directories
38 | node_modules
39 | jspm_packages
40 |
41 | # Optional npm cache directory
42 | .npm
43 |
44 | # Optional REPL history
45 | .node_repl_history
46 |
47 |
48 | ### Bower ###
49 | bower_components
50 | .bower-cache
51 | .bower-registry
52 | .bower-tmp
53 |
54 | ### IntelliJ ###
55 | .idea
56 | angular-polymer.iml
57 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | # Source files
2 | bower.json
3 | tsconfig.json
4 | tslint.json
5 | typings/
6 | typings.json
7 | *.ts
8 | !*.d.ts
9 |
10 | # Tests and testing setup
11 | *.html
12 | *.spec.js
13 | *.spec.ts
14 | *.spec.d.ts
15 | system.config.js
16 | karma.conf.js
17 | circle.yml
18 |
19 | # Docs
20 | docs/
21 |
22 | # Created by https://www.gitignore.io/api/node,bower,typings
23 |
24 | ### Node ###
25 | # Logs
26 | logs
27 | *.log
28 | npm-debug.log*
29 |
30 | # Runtime data
31 | pids
32 | *.pid
33 | *.seed
34 |
35 | # Directory for instrumented libs generated by jscoverage/JSCover
36 | lib-cov
37 |
38 | # Coverage directory used by tools like istanbul
39 | coverage
40 |
41 | # nyc test coverage
42 | .nyc_output
43 |
44 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
45 | .grunt
46 |
47 | # node-waf configuration
48 | .lock-wscript
49 |
50 | # Compiled binary addons (http://nodejs.org/api/addons.html)
51 | build/Release
52 |
53 | # Dependency directories
54 | node_modules
55 | jspm_packages
56 |
57 | # Optional npm cache directory
58 | .npm
59 |
60 | # Optional REPL history
61 | .node_repl_history
62 |
63 |
64 | ### Bower ###
65 | bower_components
66 | .bower-cache
67 | .bower-registry
68 | .bower-tmp
69 |
70 |
71 | ### Typings ###
72 | ## Ignore downloaded typings
73 | typings
74 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | Copyright 2016 Vaadin Ltd.
179 |
180 | Licensed under the Apache License, Version 2.0 (the "License");
181 | you may not use this file except in compliance with the License.
182 | You may obtain a copy of the License at
183 |
184 | http://www.apache.org/licenses/LICENSE-2.0
185 |
186 | Unless required by applicable law or agreed to in writing, software
187 | distributed under the License is distributed on an "AS IS" BASIS,
188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189 | See the License for the specific language governing permissions and
190 | limitations under the License.
191 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://circleci.com/gh/platosha/angular-polymer) [](https://www.npmjs.com/package/angular-polymer)
2 |
3 | # Angular-Polymer
4 |
5 | `angular-polymer` is a directive factory that aims at bridging the gaps between using [Polymer](https://www.polymer-project.org) based Web Components in [Angular](https://angular.io/) applications.
6 |
7 | > Note: Currently Angular-Polymer only works with Angular 2.x, or Angular-CLI 1.0.0-rc.2 and lower.
8 | > Work is being done to upgrade the library to work the latest Angular & CLI. [Want to help Contribute?](https://github.com/platosha/angular-polymer/issues/123)
9 |
10 | **In case you are using Angular 4+ and Polymer 2+** you might want to check out https://github.com/hotforfeature/origami
11 |
12 | ---
13 |
14 | ```typescript
15 | import { NgModule, CUSTOM_ELEMENTS_SCHEMA, Component } from '@angular/core';
16 | import { PolymerModule, PolymerElement } from '@vaadin/angular2-polymer';
17 |
18 | @NgModule({
19 | imports: [ PolymerModule ],
20 | declarations: [
21 | AppComponent,
22 | PolymerElement('paper-input'),
23 | PolymerElement('vaadin-combo-box')
24 | ],
25 | bootstrap: [ AppComponent ],
26 | schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
27 | })
28 | export class AppModule { }
29 |
30 | @Component({
31 | selector: 'app-component',
32 | template: `
33 |
34 |
35 | `
36 | })
37 | class AppComponent {
38 | myValue = 'A';
39 | myItems = ['A', 'B', 'C'];
40 | }
41 | ```
42 |
43 | ## Getting started
44 |
45 | See the overview for a [quick start](https://github.com/platosha/angular-polymer/blob/master/docs/overview.adoc#quick-start).
46 |
47 | See the [tutorial](https://github.com/platosha/angular-polymer/blob/master/docs/tutorial-index.adoc) for complete instructions on how to use `angular-polymer` and how to build a working application with Angular data binding and routes.
48 |
49 | If you are using [Webpack](https://webpack.github.io/) in your project, see the specific [document](https://github.com/platosha/angular-polymer/blob/master/docs/ng-cli-webpack.adoc) on how to build angular-polymer apps with webpack.
50 |
51 | ## Demo app
52 |
53 | The Expense Manager demo is an example of a real world application built using Angular and Polymer web components.
54 |
55 | - [Live demo](http://demo.vaadin.com/expense-manager-ng)
56 | - [Source code](https://github.com/vaadin/expense-manager-ng2-demo)
57 |
58 | ## Where to get Polymer web components
59 |
60 | For high quality Polymer web components, see the [Webcomponents Element Catalog](https://www.webcomponents.org/) and [Vaadin Elements](https://vaadin.com/elements).
61 |
62 | ## Development
63 |
64 | Familiarize yourself with the code and try to follow the same syntax conventions to make it easier for us to accept your pull requests.
65 |
66 | Discuss / exchange ideas and ask questions here:
67 | https://polymer.slack.com/messages/polymer-angular/
68 |
69 | ### Getting the Code
70 |
71 | 1. Clone the angular-polymer project:
72 |
73 | ```shell
74 | $ git clone https://github.com/platosha/angular-polymer.git
75 | $ cd angular-polymer
76 | ```
77 |
78 | 2. Install dependencies. We assume that you have already installed `npm` in your system.
79 |
80 | ```shell
81 | $ npm install
82 | ```
83 |
84 | ### Running Tests
85 |
86 | For running the tests you need [Bower](http://bower.io) installed.
87 |
88 | Then, you can download all bower dependencies needed by the Tests.
89 |
90 | ```shell
91 | $ bower install
92 | ```
93 |
94 | Finally, you can run the tests by typing:
95 |
96 | ```shell
97 | $ npm test
98 | ```
99 |
100 | Optionally, you can watch for the source changes and keep the tests running automatically:
101 |
102 | ```shell
103 | $ npm run test:w
104 | ```
105 |
106 | ## License
107 |
108 | Apache License 2.0
109 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular2-polymer",
3 | "description": "Angular 2 support for Polymer elements",
4 | "main": "index.js",
5 | "authors": [
6 | "Vaadin Ltd"
7 | ],
8 | "license": "Apache 2.0",
9 | "homepage": "https://github.com/vaadin/angular2-polymer",
10 | "moduleType": [],
11 | "private": false,
12 | "ignore": [
13 | "**/.*",
14 | "node_modules",
15 | "bower_components",
16 | "test",
17 | "tests"
18 | ],
19 | "devDependencies": {
20 | "polymer": "Polymer/polymer#^1.4.0",
21 | "iron-form-element-behavior": "PolymerElements/iron-form-element-behavior#^1.0.6",
22 | "paper-checkbox": "PolymerElements/paper-checkbox#^1.3.0"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | machine:
2 | node:
3 | version: 6.9.1
4 |
5 | dependencies:
6 | override:
7 | - npm install
8 | - npm run bower install
9 | cache_directories:
10 | - bower_components
11 |
12 | compile:
13 | override:
14 | - npm run lint
15 |
--------------------------------------------------------------------------------
/docs/api.adoc:
--------------------------------------------------------------------------------
1 | ---
2 | title: API Reference
3 | order: 4
4 | layout: page
5 | ---
6 |
7 | [[vaadin-angular2-polymer.api]]
8 | = Angular2-Polymer API
9 |
10 | This package consists of one generic Angular 2 directive factory method named [classname]#PolymerElement#, which is able to handle any Polymer element for easy integrating on Angular apps.
11 |
12 | == Features
13 |
14 | The [classname]#PolymerElement# is composed of a set of low level directives which would be added to the module dynamically.
15 |
16 | `changeEventsAdapterDirective`::
17 | This directive configures all the the public [propertyname]#properties#, that notify for their value change in a Polymer element, to be an Angular 2 link:https://angular.io/docs/js/latest/api/core/DirectiveMetadata-class.html+++#+++!+++#+++outputs-anchor[output].
18 | So as any change made in a property in the polymer side, will be propagated to the Angular 2 parent component.
19 |
20 | `notifyForDiffersDirective`::
21 | Configures all the public [propertyname]#properties# in a Polymer element to be an Angular 2 link:https://angular.io/docs/js/latest/api/core/DirectiveMetadata-class.html+++#+++!+++#+++inputs-anchor[input].
22 | It allows to notify changes from the Angular side to Polymer. It supports primitive types, as well as both Array and Object properties, but not its children.
23 | If you want to notify nested object changes, you can still do it by calling the Polymer's [methodname]#notifyPath# method on the element.
24 |
25 | `formElementDirective`::
26 | If the element has the Polymer Form Element Behavior, this directive is added to the module, and it configures the element to be compatible with the Angular 2 `ngForm`.
27 |
28 | `validationDirective`::
29 | It is another directive added in the case of the element has the Polymer Form Element Behavior. It sets the Polymer [propertyname]#invalid# flag based on the Angular 2 `ngControl` state.
30 |
31 | `reloadConfigurationDirective`::
32 | This directive is added to those Polymer elements that need to run a configuration function after they are initialized.
33 | It is added if the element has the [methodname]#isInitialized# and the [methodname]#reloadConfiguration# methods in its prototype.
34 |
35 | == Usage
36 |
37 | In order to use the [classname]#PolymerElement# in the [propertyname]#declarations# block of your [classname]#NgModule#, you have to import it as is shown in the example below.
38 |
39 | The only public API is the [classname]#PolymerElement(tagName: string): Array# factory method.
40 | The argument [propertyname]#tagName# is mandatory, and must match the tag name of the Polymer element.
41 | The factory returns the set of necessary directives for the given Polymer element.
42 | Hence, you have to add the [classname]#PolymerElement# directive as many times as different Polymer elements you are using in your Angular module.
43 |
44 | [source,typescript]
45 | ----
46 | import { Component, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
47 | import { BrowserModule } from '@angular/platform-browser';
48 | import { PolymerElement } from '@vaadin/angular2-polymer';
49 |
50 | @Component({
51 | selector: 'app-root',
52 | template: `
53 |
54 |
55 |
56 | `
57 | })
58 | class AppComponent {
59 | myValue = 'A';
60 | myItems = ['A', 'B', 'C'];
61 | }
62 |
63 | @NgModule({
64 | imports: [ BrowserModule ],
65 | declarations: [
66 | AppComponent,
67 | PolymerElement('iron-icon'),
68 | PolymerElement('paper-input'),
69 | PolymerElement('vaadin-combo-box')
70 | ],
71 | bootstrap: [ AppComponent ],
72 | schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
73 | })
74 | export class AppModule { }
75 | ----
76 |
--------------------------------------------------------------------------------
/docs/best-practices.adoc:
--------------------------------------------------------------------------------
1 | ---
2 | title: Best practices
3 | order: 1
4 | layout: page
5 | ---
6 |
7 | [[angular-polymer.best-practices]]
8 | = Angular Polymer best practices
9 |
10 | This document describes various best practices when using the `angular-polymer` library.
11 |
12 | == Lists (with `iron-list`)
13 | Angular has it's own mechanism for dealing with `` elements. That is why something like this:
14 | ``` html
15 |
16 |
17 |
18 | Name: {{item.value}}
19 |
20 |
21 |
22 | ```
23 | Is *not* possible. Here is some more information: https://github.com/PolymerElements/iron-list/issues/291#issuecomment-251354454
24 |
25 | === Best practice
26 | Best practice at the moment is to wrap `` with its template in another Polymer element, that is registered outside Angular templates. For example, create my-list.html:
27 |
28 | ``` html
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Name: [[item.name]]
38 |
39 |
40 |
41 |
42 |
43 |
51 |
52 | ```
53 |
54 | Then import it in index.html, just like any other Polymer element:
55 |
56 | ``` html
57 | ...
58 |
59 | ...
60 |
61 |
62 | ...
63 | ```
64 |
65 | Then you can use the `` element in declarations (`PolymerElement('my-list')`), as well as in Angular templates. The `` template was already defined in ``, therefore we don't have it in Angular templates:
66 |
67 | ``` html
68 |
69 | ```
70 |
71 | It requires a bit of work, though: you have to manually bypass all the properties and methods you use in `` through ``. In the example above, only the `items` property is bypassed.
72 |
73 | == Forms
74 | As `PolymerElement('x-element')` looks for elements named `` it doesn't work with Polymer elements that have been extended from native elements like `