I am following this YouTube video and I have seen every previous video in the tutorial series.
This is my code:
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="elements/hello-world.html">
</head>
<body>
<hello-world></hello-world>
</body>
</html>
And the second page:
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name='hello-world' noscript>
<template>
<h1>Hello World</h1>
</template>
</polymer-element>
But my page is still blank, what am I doing wrong?
I use Wamp.
It's always happen to me if i'm not correctly import an element or library. So make sure all path locations are correct.
Make sure you use 0.5 version because in 0.8 custom element declaration is using <dom-module id="element-name"></dom-module>
First check your polymer version. it is found on bower.json under dependencies
check "polymer": "Polymer/polymer#^1.7.0" as you can see mine is 1.7.0. if you are using polymer 1.0 and above. the custom element declaration has been changed.
Here is a detailed note on what you have to do.
Change <script src="bower_components/webcomponentsjs/webcomponents.js"></script> to <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
Custom element declaration has also been changed from
<polymer-element name="hello-world">
<template>
<div>Hello World</div>
</template>
<script>
Polymer();
</script>
</polymer-element>
to
<dom-module id="hello-world">
<template>
<div>Hello World</div>
</template>
<script>
Polymer({
is: "hello-world"
});
</script>
</dom-module>
Check The Migration Guide Page https://www.polymer-project.org/1.0/docs/migration
Related
I can run all the following simplified code in jsbin without any error. The size of the real code is large - it contains many imports, and properties and functions within Polymer().
The real version of the following simplified version of index.html has been working fine with both Iceweasel and Chromium in localhost:
(version 1)
<!DOCTYPE html>
<html>
<head>
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
</head>
<body>
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
HTMLImports.whenReady(function(){
Polymer({
is: 'my-element'
});
});
</script>
<my-element></my-element>
</body>
</html>
However, when the real version of above index.html is served from remote host, the function passed to HTMLImports.whenReady never gets called. Besides, Iceweal complains ReferenceError: Polymer is not defined.
Then I borrow this technique to have this version (version 2):
<!DOCTYPE html>
<html>
<head>
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
</head>
<body>
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
var init=function(){
Polymer({
is: 'my-element'
});
};
if(HTMLImports.ready)
init();
else{
console.log("called"); //Always comes here!
HTMLImports.whenReady(init);
}
</script>
<my-element></my-element>
</body>
</html>
comment for above version: The real large version always runs to HTMLImports.whenReady(init); but function init() never gets called.
I also tried this technique and make the simplified code look like this (version 3):
<!DOCTYPE html>
<html>
<head>
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
</head>
<body>
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
document.addEventListener('WebComponentsReady',function(){
console.log("called"); //Never gets called!
Polymer({
is: 'my-element'
});
});
</script>
<my-element></my-element>
</body>
</html>
console.log() in the above version is never executed.
How do I change the code so that it guarantees every element will be properly loaded even in cases where the file size is big and network and server are slow?
Thank you in advance!
(edit 1)
My browsers respond today differently than last night:
version 1: Both Iceweasel (i.e. Firefox?) and Chromium (i.e. Chrome?) remain silent and yield a blank page without any error or warning in developer's console.
version 2, version 3, and #akc42's version: Chromium displays the expected correct page. Iceweasel complains ReferenceError: Polymer is not defined.
(edit 2)
My test results are different from those 20 minutes ago as follows:
version 2: Chromium gives blank page. Iceweasel complains ReferenceError: Polymer is not defined.
version 3: Chromium complains Uncaught ReferenceError: Polymer is not defined. Iceweasel complains `ReferenceError: Polymer is not defined'.
I am reading the note here. I will split index.html into two and see if it make any different results.
(edit 3)
I am sad to report that splitting index.html into two files does not make any difference - both Chromium and Iceweasel quietly give blank page.
(version 4):
index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="import" href="my-element.html">
</head>
<body>
<my-element></my-element>
</body>
</html>
my-element.html (version 4a):
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
HTMLImports.whenReady(function(){
console.log("called"); //Never gets called!
Polymer({
is: 'my-element'
});
});
</script>
my-element.html (version 4b):
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element'
});
</script>
Many thanks to the helps from #ScottMiles and #akc42 !
My troubles turns out to come from ClouldFlare's cloud services. Their cache system heavily rewrites nearly all of my import files.
After I bypass CloudFlare's cloud, Chromium is happy with versions 1 and 4; Iceweasel complains `ReferenceError: Polymer is not defined' but displays the correct page with version 4.
Nevertheless, I much like their services. So, I will see if I can acquire their helps. (Currently I am using their free services)
Meanwhile, I will try vulcanize to see if the compressed single file is immune to ClouldFlare's cache system.
If anyone is generous to share your successful experience with ClouldFlare and Polymer, I will be much grateful, too.
(edit)
After I bypass CloudFlare's cloud, both Chromium and Iceweasel works flawlessly with all above 4 versions.
(edit 2)
I am pleased to quote ClouldFlare's swift reply to my request for help as follows:
This is strange- can you reenable CloudFlare on your trial subdomain and try a few things to see if we can narrow this down:
- Go to the 'Speed' page on the dashboard.
- Disable Rocket Loader by setting it to off
- If this doesn't correct the issue, try toggling the Minify options off at the top of the Speed page.
Rocket loader is a beta feature and so can sometimes cause issues- it is difficult to ensure 100% compatibility with all javascript on the web.
After I disabled Rocket Loader as ClouldFlare's expert told me, all the issues I encountered are gone! I am happy to mark this question as answered.
You don't need to wait for anything to call Polymer({is:'my-element'}); What you do do is have an ready function is the object you call Polymer with to tell you when its ready to go.
<!DOCTYPE html>
<html>
<head>
<script src="http://polygit.org/components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="http://polygit.org/components/polymer/polymer.html">
<link rel="import" href="http://polygit.org/components/paper-input/paper-input.html">
</head>
<body>
<dom-module id="my-element">
<template>
<paper-input></paper-input>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element',
ready: function() {
console.log('element ready')
}
});
</script>
<my-element></my-element>
</body>
</html>
Normally you would declare the my-element object in another file that you would import.
Also, if you want to use any databinding at the index.html level you can use the element, which you then can listen for all elements in it complete, so
<body>
<template is="dom-bind" id="app">
<my-element></my-element>
</template>
<script>
var app = document.getElementById('app');
app.addEventListener('dom-change', function() {
//perform app initialisation here
});
</script>
</body>
Hello
I'm starting with Polymer 1.0 and I'm trying to create my first element and load into an html page. I'm using Chrome Dev Editor, the project was created correctly because I could load all the example. After that I eliminate all the example code and create a:
Folder "elements" into the project
"hello-world.html" with the following code:
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="hello-world" noscript>
<template>
<h1>Hello World</h1>
</template>
Updated the code in the "index.html" file
<!doctype html>
<html>
<head>
<title>PolyExample</title>
<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="elements/hello-world.html">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Test Polymer</h1>
<hello-world></hello-world>
</body>
</html>
I will appreciate any help about this
Thanks in advance
Your code has a serious problem in the way you create your element,
You use a dom-module element to create a new element and you need to write some JS to initialize the element. Below is an example
<link rel="import"
href="bower_components/polymer/polymer.html">
<dom-module id="hello-world">
<template>
<h1>Hello World</h1>
</template>
<script>
Polymer({
is: "hello-world"
});
</script>
</dom-module>
The script tag with that code is essential for your element to work.
This is probably as simple as it gets.
To read more on that follow the link:
https://www.polymer-project.org/1.0/docs/start/quick-tour.html
I'm trying to render a simple Polymer-element. I have followed the docs and it is not rendered. The weird thing is that a more complex polymer tags do work (such as <dom-module id=""> ), but no luck with <polymer-element>.
index.html
<!DOCTYPE html>
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="elements/daniel-element.html">
<title>Polymer Learning</title>
</head>
<body>
<daniel-element></daniel-element>
</body>
</html>
daniel-element.html
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="fav-color">
<template>
This is <b>{{owner}}</b>'s fav-color element.
{{owner}} likes the color
<span style="color: {{color}}">{{color}}</span>.
</template>
<script>
Polymer({
owner: "Daniel",
color: "red"
});
</script>
</polymer-element>
When I run:
python -m SimpleHTTPServer
OR
polyserve
The browser does not render the element.
I have looked on this subject and did not found a solution.. thanks before.
The <polymer-element> tag was used in older versions of Polymer. With 1.0 you need to use <dom-module id=""> which does work as you have noticed. Have a look at the migration guide to find out more on specifying local DOM in 1.0.
I'm following the Polymer tutorial at https://www.youtube.com/watch?v=wId1gMzriRE
I'm using Polymer 1.0 (the tutorial is an older version). I had changed the platform.js to webcomponents.js.
Now my index.html is as
<!doctype html>
<html>
<head>
<title>Polymer Trial</title>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="elements/hello-world.html">
</head>
<body>
<h2>Test</h2>
<hello-world></hello-world>
</body>
</html>
And I've my element file hello-world.html as
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="hello-world" noscript>
<template>
<h1>Hello World!</h1>
</template>
</polymer-element>
But all I get in the browser is as below; no "Hello World!" is rendered.
Am I missing something? How can I figure out where is the issue?
Attached below is my directory structure.
The older tutorial will not work for Polymer 1.0, as there are many drastic changes. In the new version, a Hello World would look like:
<dom-module id="hello-world">
<template>
<h1>Hello world!</h1>
</template>
</dom-module>
<script>
Polymer({
is: 'hello-world'
});
</script>
More information can be found in the Polymer documentation at https://www.polymer-project.org/1.0/docs/devguide/feature-overview.html
Trying to display hello world using elements but nothing happens any help?
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="elements/hello-world.html">
</head>
<body unresolved>
<hello-world></hello-world>
</body>
</html>
hello-world.html
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="hello-world" nonscript>
<template>
<h2>Hello World</h2>
</template>
</polymer-element>
Code for "hello-world.html" is now:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="hello-world">
<template>
<h1>Hello World</h1>
</template>
<script>
Polymer ({ is: "hello-world", });
</script>
</dom-module>
If you are using polymer version 0.8 or 0.9, then <polymer-element ... should be <dom-module ...
See more from polymer site:
https://www.polymer-project.org/0.9/docs/start/quick-tour.html
You have a typo, nonscript needs to be noscript.
<polymer-element name="hello-world" noscript>
I have the same problem and dont find the mistake.
index.html
<html>
<head>
<title>Polymer-Application</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--<script src="bower_components/jquery/dist/jquery.min.js"></script>-->
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
<!-- file is available, auto completed by api -->
<link rel="import" href="hello/hello.html">
<!-- file is available, auto completed by api -->
<!-- netbeans doesn't know relation import -->
</head>
<body>
<h1>My first Polymer-Application</h1>
<hello></hello>
</body>
</html>
hello/hello.html
<link rel="import" href="../bower_components/polymer/polymer.html">
<!-- file is available, auto complete by api -->
<polymer-element name="hello" noscript>
<template>
<h1>Hello Polymer world</h1>
</template>
</polymer-element>
My platfrom is:
Win 8.1
nodejs
bower
polymer (installed over bower, folders and files are availible)
git
netbeans dev edition (as editor)
xammp (as apache webserver)
tested with chrome, firefox and ie10 and the custom element is not be shown. i don't think it's a browser problem. it's the simpliest element you can write, but why did it not work?
Edit:
tested it on a clean ubuntu installation. and it still does not work?
i also tested original code from the polymer page and this won't work too.
am i to stupid for copy paste?
Edit 2:
i found it an have running my polymer apps. If i use Polymer 1.0.9 i should not read the tutorial for 0.5.0
changes:
index.html:
<!DOCTYPE html>
<html>
<head>
...
<script scr="bower_components/webcomponents-lite.min.js"></script>
<!-- the lite edition is needet since polymer version 0.8 -->
<link rel="import" href="hello/hello.html">
...
</head>
<body>
<hello></hello>
</body>
</html>
hello/hello.html:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="hello">
<!-- its not longer a polymer-element. we have to use dom-module and id and the noscript option is not longer supported -->
<template>
<template>
<script>
// everytime you need to initialize a Polymer object
Polymer({
is: 'hello' // must be set now
});
</script>
</dom-module>
if you want to work with parameters you need to set it in the polymer ready function and every placeholder must be surrounded by a html tag like span without any other content in it.
Replace the line
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
with
<script src="../bower_components/webcomponentsjs/webcomponents.js"></script>
This should fix the issue.