SlideShare une entreprise Scribd logo
1  sur  21
Polymer 1.0
Jason
What is Polymer?
●The Polymer library is designed to make it easier and faster for developers to
create great, reusable components for the modern web.
●With custom elements, you can extend the vocabulary of HTML with your own
elements. Elements that provide sophisticated UI.
Web Component
●HTML Template
●Custom Element
●Shadow DOM
●HTML Import
Installing with Bower
Project setup
> bower init
> bower install --save Polymer
> bower update
Quick tour of Polymer
● Register an element
● Add local DOM
● Compose with local DOM
● Use data binding
● Declare a property
● Bind to a property
Register an element
● To register a new element, call the Polymer function, which registers a new
element with the browser. Registering an element associates a tag name with a
prototype, so you can add properties and methods to your custom element.
The custom element’s name must contain a dash (-).
Register an element
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="first-component.html">
</head>
<body>
<first-component></first-component>
</body>
</html>
first-component.html
<link rel="import"
href="bower_components/polymer/polymer.html">
<script>
Polymer({
is: "first-component",
ready: function() {
this.textContent = "I'm a proto-element."
}
});
</script>
Custom Element Lifecycle callbacks
● created instead of createdCallback
● attached instead of attachedCallback
● detached instead of detachedCallback
● attributeChanged instead of attributeChangedCallback
Custom Element Lifecycle callbacks
Polymer({
is: "polymer-lifecycle",
ready: function(){ },
created: function() {},
attached: function() {},
detached: function() {},
attributeChanged: function(name, type) {
console.log(this.localName + '#' + this.id + ' attribute ' + name + ' was changed to ' +
this.getAttribute(name));
}
});
created ready attached
Add local DOM
● Many elements include some internal DOM nodes to implement the element’s
UI and behavior. Polymer calls this local DOM, and it provides an easy way to
specify it.
● Local DOM is encapsulated inside the element.
Add local DOM
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="dom-element.html">
</head>
<body>
<dom-element></dom-element>
</body>
</html>
dom-element.html
<link rel="import"
href="bower_components/polymer/polymer.html">
<dom-module id="dom-element">
<template>
<p>I'm a DOM element. </p>
</template>
<script>
Polymer({
is: "dom-element"
});
</script>
</dom-module>
Compose with local DOM
● Local DOM lets you control composition. The element’s children can be
distributed so they render as if they were inserted into the local DOM tree.
Compose with local DOM
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="picture-frame.html">
</head>
<body>
<picture-frame>
<img src=”image1.jpg” alt=”” />
</picture-frame>
</body>
</html>
picture-frame.html
<link rel="import" href="polymer/polymer.html">
<dom-module id="picture-frame">
<template>
<style>
div { background-color: #ccc; }
</style>
<div>
<content></content>
</div>
</template>
<script>
Polymer({ is: "picture-frame" });
</script>
</dom-module>
Use data binding
● 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 ({{}}). The {{}} is replaced by the value of the
property referenced between the brackets.
Use data binding
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="name-tag.html">
</head>
<body>
<name-tag></name-tag>
</body>
</html>
name-tag.html
<link rel="import" href="polymer.html">
<dom-module id="name-tag">
<template>
This is <b>{{owner}}</b>'s name-tag element.
</template>
<script>
Polymer({
is: "name-tag",
ready: function() {
this.owner = "Daniel";
} });
</script>
</dom-module>
Declare a property
● Properties are an important part of an element’s public API. Polymer declared
properties support a number of common patterns for properties — setting
default values, configuring properties from markup, observing property
changes, and more..
Declare a property
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="configurable-name-tag.html">
</head>
<body>
<configurable-name-tag
owner="Scott"></configurable-name-tag>
</body>
</html>
configurable-name-tag.html
<dom-module id="configurable-name-tag">
<template>
This is <b>{{owner}}</b>'s configurable-name-tag .
</template>
<script>
Polymer({
is: "configurable-name-tag",
properties: {
owner: {
type: String,
value: "Daniel"
}
}
});
</script>
</dom-module>
Bind to a property
● In addition to text content, you can bind to an element’s properties (using
property-name="{{binding}}"). Polymer properties can optionally support
two-way binding.
●This example uses two-way binding: binding the value of a custom input
element (iron-input) to the element’s owner property, so it’s updated as the user
types
Bind to a property
Index.html
<html>
<head>
<script src="webcomponents-lite.min.js"></script>
<link rel="import" href="editable-name-tag.html">
</head>
<body>
<editable-name-tag></editable-name-tag>
</body>
</html>
editable-name-tag.html
<link rel="import" href="polymer.html">
<link rel="import" href="iron-input/iron-input.html">
<dom-module id="editable-name-tag">
<template>
This is a <strong>{{owner}}</strong>'s editable-name-tag.
<input is="iron-input" bind-value="{{owner}}"/>
</template>
<script>
Polymer({
is: "editable-name-tag",
properties: {
owner: {
type: String,
value: "Daniel"
} } });
</script>
</dom-module>
Reference
Polymer 1.0 - https://www.polymer-project.org/1.0/docs/
Shadow - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Shadow
Html Import - http://www.html5rocks.com/en/tutorials/webcomponents/imports/
Custom Elements - http://www.html5rocks.com/en/tutorials/webcomponents/customelements/

Contenu connexe

Tendances

Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
Rich Bradshaw
 

Tendances (20)

Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Polymer vs other libraries (Devfest Ukraine 2015)
Polymer vs other libraries (Devfest Ukraine 2015)Polymer vs other libraries (Devfest Ukraine 2015)
Polymer vs other libraries (Devfest Ukraine 2015)
 
Polymer, A Web Component Polyfill Library
Polymer, A Web Component Polyfill LibraryPolymer, A Web Component Polyfill Library
Polymer, A Web Component Polyfill Library
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Web Components
Web ComponentsWeb Components
Web Components
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Polymer & the web components revolution 6:25:14
Polymer & the web components revolution 6:25:14Polymer & the web components revolution 6:25:14
Polymer & the web components revolution 6:25:14
 
Web Components
Web ComponentsWeb Components
Web Components
 
Web Components & Polymer 1.0 (Webinale Berlin)
Web Components & Polymer 1.0 (Webinale Berlin)Web Components & Polymer 1.0 (Webinale Berlin)
Web Components & Polymer 1.0 (Webinale Berlin)
 
Custom Elements with Polymer Web Components #econfpsu16
Custom Elements with Polymer Web Components #econfpsu16Custom Elements with Polymer Web Components #econfpsu16
Custom Elements with Polymer Web Components #econfpsu16
 
Web Components
Web ComponentsWeb Components
Web Components
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
Reaching for the Future with Web Components and Polymer
Reaching for the Future with Web Components and PolymerReaching for the Future with Web Components and Polymer
Reaching for the Future with Web Components and Polymer
 
Unlock the next era of UI design with Polymer
Unlock the next era of UI design with PolymerUnlock the next era of UI design with Polymer
Unlock the next era of UI design with Polymer
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014Polymer - Welcome to the Future @ PyGrunn 08/07/2014
Polymer - Welcome to the Future @ PyGrunn 08/07/2014
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
Exploring Critical Rendering Path
Exploring Critical Rendering PathExploring Critical Rendering Path
Exploring Critical Rendering Path
 
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
 

En vedette (7)

Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 
Conociendo Angular 2
Conociendo Angular 2Conociendo Angular 2
Conociendo Angular 2
 
Web apps con angular y material design
Web apps con angular y material designWeb apps con angular y material design
Web apps con angular y material design
 
PostCss
PostCssPostCss
PostCss
 
Progressive web apps with polymer
Progressive web apps with polymerProgressive web apps with polymer
Progressive web apps with polymer
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java Developers
 
Creating HTML Pages
Creating HTML PagesCreating HTML Pages
Creating HTML Pages
 

Similaire à Polymer

Intro to polymer-Devfest Yaoundé 2013
Intro to polymer-Devfest Yaoundé 2013Intro to polymer-Devfest Yaoundé 2013
Intro to polymer-Devfest Yaoundé 2013
gdgyaounde
 
Александр Кашеверов - Polymer
Александр Кашеверов - PolymerАлександр Кашеверов - Polymer
Александр Кашеверов - Polymer
DataArt
 

Similaire à Polymer (20)

Polytechnic 1.0 Granada
Polytechnic 1.0 GranadaPolytechnic 1.0 Granada
Polytechnic 1.0 Granada
 
Polymer - Una bella historia de amor
Polymer - Una bella historia de amorPolymer - Una bella historia de amor
Polymer - Una bella historia de amor
 
Intro to polymer-Devfest Yaoundé 2013
Intro to polymer-Devfest Yaoundé 2013Intro to polymer-Devfest Yaoundé 2013
Intro to polymer-Devfest Yaoundé 2013
 
Web components
Web componentsWeb components
Web components
 
Web components
Web componentsWeb components
Web components
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
Polymer - Lego for the web!
Polymer - Lego for the web!Polymer - Lego for the web!
Polymer - Lego for the web!
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 
Polymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot CampPolymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot Camp
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...
 
Polymer Code Lab in Dart - DevFest Kraków 2014
Polymer Code Lab in Dart - DevFest Kraków 2014Polymer Code Lab in Dart - DevFest Kraków 2014
Polymer Code Lab in Dart - DevFest Kraków 2014
 
Rawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web ComponentsRawnet Lightning Talk - Web Components
Rawnet Lightning Talk - Web Components
 
Up & Running with Polymer
Up & Running with PolymerUp & Running with Polymer
Up & Running with Polymer
 
Introduction to web components
Introduction to web componentsIntroduction to web components
Introduction to web components
 
Polymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest FloridaPolymer-Powered Design Systems - DevFest Florida
Polymer-Powered Design Systems - DevFest Florida
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
 
Александр Кашеверов - Polymer
Александр Кашеверов - PolymerАлександр Кашеверов - Polymer
Александр Кашеверов - Polymer
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 

Plus de LearningTech (20)

vim
vimvim
vim
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

Polymer

  • 2. What is Polymer? ●The Polymer library is designed to make it easier and faster for developers to create great, reusable components for the modern web. ●With custom elements, you can extend the vocabulary of HTML with your own elements. Elements that provide sophisticated UI.
  • 3.
  • 4. Web Component ●HTML Template ●Custom Element ●Shadow DOM ●HTML Import
  • 5. Installing with Bower Project setup > bower init > bower install --save Polymer > bower update
  • 6. Quick tour of Polymer ● Register an element ● Add local DOM ● Compose with local DOM ● Use data binding ● Declare a property ● Bind to a property
  • 7. Register an element ● To register a new element, call the Polymer function, which registers a new element with the browser. Registering an element associates a tag name with a prototype, so you can add properties and methods to your custom element. The custom element’s name must contain a dash (-).
  • 8. Register an element Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="first-component.html"> </head> <body> <first-component></first-component> </body> </html> first-component.html <link rel="import" href="bower_components/polymer/polymer.html"> <script> Polymer({ is: "first-component", ready: function() { this.textContent = "I'm a proto-element." } }); </script>
  • 9. Custom Element Lifecycle callbacks ● created instead of createdCallback ● attached instead of attachedCallback ● detached instead of detachedCallback ● attributeChanged instead of attributeChangedCallback
  • 10. Custom Element Lifecycle callbacks Polymer({ is: "polymer-lifecycle", ready: function(){ }, created: function() {}, attached: function() {}, detached: function() {}, attributeChanged: function(name, type) { console.log(this.localName + '#' + this.id + ' attribute ' + name + ' was changed to ' + this.getAttribute(name)); } }); created ready attached
  • 11. Add local DOM ● Many elements include some internal DOM nodes to implement the element’s UI and behavior. Polymer calls this local DOM, and it provides an easy way to specify it. ● Local DOM is encapsulated inside the element.
  • 12. Add local DOM Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="dom-element.html"> </head> <body> <dom-element></dom-element> </body> </html> dom-element.html <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="dom-element"> <template> <p>I'm a DOM element. </p> </template> <script> Polymer({ is: "dom-element" }); </script> </dom-module>
  • 13. Compose with local DOM ● Local DOM lets you control composition. The element’s children can be distributed so they render as if they were inserted into the local DOM tree.
  • 14. Compose with local DOM Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="picture-frame.html"> </head> <body> <picture-frame> <img src=”image1.jpg” alt=”” /> </picture-frame> </body> </html> picture-frame.html <link rel="import" href="polymer/polymer.html"> <dom-module id="picture-frame"> <template> <style> div { background-color: #ccc; } </style> <div> <content></content> </div> </template> <script> Polymer({ is: "picture-frame" }); </script> </dom-module>
  • 15. Use data binding ● 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 ({{}}). The {{}} is replaced by the value of the property referenced between the brackets.
  • 16. Use data binding Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="name-tag.html"> </head> <body> <name-tag></name-tag> </body> </html> name-tag.html <link rel="import" href="polymer.html"> <dom-module id="name-tag"> <template> This is <b>{{owner}}</b>'s name-tag element. </template> <script> Polymer({ is: "name-tag", ready: function() { this.owner = "Daniel"; } }); </script> </dom-module>
  • 17. Declare a property ● Properties are an important part of an element’s public API. Polymer declared properties support a number of common patterns for properties — setting default values, configuring properties from markup, observing property changes, and more..
  • 18. Declare a property Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="configurable-name-tag.html"> </head> <body> <configurable-name-tag owner="Scott"></configurable-name-tag> </body> </html> configurable-name-tag.html <dom-module id="configurable-name-tag"> <template> This is <b>{{owner}}</b>'s configurable-name-tag . </template> <script> Polymer({ is: "configurable-name-tag", properties: { owner: { type: String, value: "Daniel" } } }); </script> </dom-module>
  • 19. Bind to a property ● In addition to text content, you can bind to an element’s properties (using property-name="{{binding}}"). Polymer properties can optionally support two-way binding. ●This example uses two-way binding: binding the value of a custom input element (iron-input) to the element’s owner property, so it’s updated as the user types
  • 20. Bind to a property Index.html <html> <head> <script src="webcomponents-lite.min.js"></script> <link rel="import" href="editable-name-tag.html"> </head> <body> <editable-name-tag></editable-name-tag> </body> </html> editable-name-tag.html <link rel="import" href="polymer.html"> <link rel="import" href="iron-input/iron-input.html"> <dom-module id="editable-name-tag"> <template> This is a <strong>{{owner}}</strong>'s editable-name-tag. <input is="iron-input" bind-value="{{owner}}"/> </template> <script> Polymer({ is: "editable-name-tag", properties: { owner: { type: String, value: "Daniel" } } }); </script> </dom-module>
  • 21. Reference Polymer 1.0 - https://www.polymer-project.org/1.0/docs/ Shadow - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Shadow Html Import - http://www.html5rocks.com/en/tutorials/webcomponents/imports/ Custom Elements - http://www.html5rocks.com/en/tutorials/webcomponents/customelements/

Notes de l'éditeur

  1. http://bbs.logdown.com/posts/210337-introduce-web-component-of-beginners-mind
  2. http://bbs.logdown.com/posts/210337-introduce-web-component-of-beginners-mind https://blog.othree.net/log/2013/11/27/web-component/ https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Shadow
  3. https://www.polymer-project.org/1.0/docs/start/quick-tour.html
  4. https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html