Polymer elements with JavaScript interop
In this recipe, we will show you how to work with a JavaScript object in a Polymer component. You can find the code in the project pol_js
.
How to do it...
- The script starts with
web\index.html
, where a component with the namepol-js
is imported through<link rel="import"href="pol_js.html">
and instantiated through<pol-js></pol-js>
.From this, we know that the component is defined in
pol_js.html
, and its code is in a file namedpol_js.dart
. For a discussion of the other tags, refer to the first recipe. - The
index.html
file also includes a JavaScriptperson.js
object:function Person(name, gender) { this.name = name; this.gender = gender; this.greeting = function(otherPerson) { alert('I greet you ' + otherPerson.name); }; } Person.prototype.sayHello = function(times) { return times + ' x: hello, I am ' + this.name; };
- The structure of the component is outlined in
pol_js.html
:<link rel="...