You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/start/creatingelements.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -124,7 +124,7 @@ detailed information on each of these features.
124
124
125
125
When you're creating a new element, you'll often need to expose a [public API](/docs/polymer/polymer.html#published-properties) so users can configure it. To define a public API, include a `<script>` tag that calls `{{site.project_title}}('your-tagname')`. The `{{site.project_title}}(...)` constructor is a convenience wrapper for [`document.registerElement`](/platform/custom-elements.html#documentregister), but also endows the element with special features like data binding and event mapping. Its first argument is the name of the element you're creating. The second argument (optional) is an object that defines your element's prototype.
126
126
127
-
{% include samples/tk-element-proto.html %}
127
+
{% include samples/proto-element.html %}
128
128
129
129
### Adding lifecycle methods
130
130
@@ -133,15 +133,15 @@ When you're creating a new element, you'll often need to expose a [public API](/
133
133
When a custom element has been registered it calls its `created()` callback (if one has been defined). When {{site.project_title}} finishes its initialization, the `ready()` method is called.
134
134
The `ready` callback is a great place to do constructor-like initialization work.
135
135
136
-
{% include samples/tk-element-created.html %}
136
+
{% include samples/ready-element.html %}
137
137
138
138
Learn more about all of the [lifecycle callbacks](/docs/polymer/polymer.html#lifecyclemethods).
139
139
140
140
### Declarative data binding
141
141
142
142
Data binding is a great way to quickly propagate changes in your element and reduce boilerplate code. You can bind properties in your component using the "double-mustache" syntax (`{%raw%}{{}}{%endraw%}`). The `{%raw%}{{}}{%endraw%}` is replaced by the value of the property referenced between the brackets.
143
143
144
-
{% include samples/tk-element-databinding.html %}
144
+
{% include samples/name-tag.html %}
145
145
146
146
Note: {{site.project_title}}'s data-binding is powered under the covers by a sub-library called [TemplateBinding](/docs/polymer/template.html), designed for other libraries to build on top of.
147
147
{: .alert .alert-info}
@@ -150,13 +150,13 @@ Note: {{site.project_title}}'s data-binding is powered under the covers by a sub
150
150
151
151
You can use binding expressions in most HTML markup, except for tag names themselves. In the following example, we create a new property on our component named `color` whose value is bound to the value of the `color` style applied to the custom element. Bindings ensure that any time a property like `color` is changed, the new value will be propagated to all binding points.
152
152
153
-
{% include samples/tk-element-databinding-color.html %}
153
+
{% include samples/fav-color.html %}
154
154
155
155
#### Binding between components and built-in elements {#bindingtobuiltin}
156
156
157
157
You can use bindings with built-in elements just like you would with Polymer elements. This is a great way to leverage existing APIs to build complex components. The following example demonstrates binding component properties to attributes of native input elements.
158
158
159
-
{% include samples/tk-binding-to-elements.html %}
159
+
{% include samples/age-slider.html %}
160
160
161
161
**Note:** Giving `age` an initial value `25` gives {{site.project_title}}
162
162
a hint that this property is an integer.
@@ -175,7 +175,7 @@ _Publish_ a property by listing it in the `attributes` attribute in your `<polym
175
175
The following example defines two data-bound properties on the element, `owner` and `color`,
176
176
and gives them default values:
177
177
178
-
{% include samples/tk-element-property-public.html %}
178
+
{% include samples/color-picker.html %}
179
179
180
180
In this example the user overrides the defaults for `owner` and `color`
181
181
by configuring the element with initial attribute values (e.g. `<color-picker owner="Scott" color="blue">`).
@@ -189,7 +189,7 @@ by configuring the element with initial attribute values (e.g. `<color-picker ow
189
189
190
190
The use of the `id` attribute has traditionally been discouraged as an anti-pattern because the document requires element IDs to be unique. Shadow DOM, on the other hand, is a self-contained document-like subtree; IDs in that subtree do not interact with IDs in other trees. This means the use of IDs in Shadow DOM is not only permissible, it's actually encouraged. Each {{site.project_title}} element generates a map of IDs to node references in the element's template. This map is accessible as `$` on the element and can be used to quickly select the node you wish to work with.
191
191
192
-
{% include samples/tk-node-finding.html %}
192
+
{% include samples/editable-color-picker.html %}
193
193
194
194
[Learn more about automatic node finding](/docs/polymer/polymer.html#automatic-node-finding)
0 commit comments