Search code examples
javascriptweb-componentpolymer-1.0custom-element

Polymer 1.0 auto binding templates


I am trying to get auto binding template to work with out success. This is what I have done so far. The page doesn't render with the value of "greeting" . It outputs {{greeting}}.

<!doctype html>
<html lang="">
<head>

  <link rel="stylesheet" href="styles/main.css">
  <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="bower_components/polymer/polymer.html">
</head>
<body>
   <template is="dom-bind" id="app" >
    <span>  {{greeting}} </span>
  </template>
  <script src="scripts/app.js"></script>
</body>
</html>

app.js

(function(document) {
  'use strict';
  var app = document.querySelector('#app');
  app.greeting = "Hello";

})(document);

It works with Polymer 0.5.5 http://plnkr.co/edit/fmL9xQEXKwnINzdL3rBj?p=preview


Solution

  • Your {{greeting}} binding must be the only content of a tag (Polymer documentation: Binding to text content). You need to remove the surrounding whitespace:

    <template is="dom-bind" id="app" >
      <span>{{greeting}}</span>
    </template>