Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Error in example from /devguide/templates.html#dom-bind #1275

Closed
tomalec opened this issue Jul 27, 2015 · 3 comments
Closed

Error in example from /devguide/templates.html#dom-bind #1275

tomalec opened this issue Jul 27, 2015 · 3 comments

Comments

@tomalec
Copy link

tomalec commented Jul 27, 2015

After copy'n'pasing example from https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-bind I get:

index.html:29 Uncaught TypeError: Cannot read property 'addEventListener' of null

I suspect it's because <template id="t" is="dom-repeat" items="{{data}}"> is not yet stamped from <template is="dom-bind">.

tomalec added a commit to tomalec/docs that referenced this issue Jul 27, 2015
@tomalec
Copy link
Author

tomalec commented Jul 27, 2015

I posted a PR for it #1276
As dom-change event works fine for root dom-bind element.

I tried to make it work for nested templates but with no luck

<body>

  <!-- Wrap elements with auto-binding template to -->
  <!-- allow use of Polymer bindings in main document -->
  <template is="dom-bind" id="r">
    List:
    <iron-ajax url="http://..." last-response="{{data}}"></iron-ajax>

    <template id="t" is="dom-repeat" items="{{data}}">
        <div>first:<span>{{item.first}}</span> last:<span>{{item.last}}</span></div>
    </template>

  </template>

</body>
<script>
  var r = document.querySelector('#r');

  // The dom-change event signifies when the template has stamped its DOM.
  r.addEventListener('dom-change', function() {
    // auto-binding template is ready.
    var t = document.querySelector('#t');
    console.log("Root dom-bind works!");

    // The dom-change event signifies when the template has stamped its DOM.
    t.addEventListener('dom-change', function() {
    // dom-repeat template is ready.
      console.log("Does nested dom-repeat work?");
    });
  });
</script>

Is there a way to do something like this?

@tomalec
Copy link
Author

tomalec commented Jul 28, 2015

Ok, above will work, once I will add auto attribute to <iron-ajax>:

<iron-ajax url="/path/to/json/api" last-response="{{data}}" auto></iron-ajax>

@tomalec
Copy link
Author

tomalec commented Jul 30, 2015

Fixed by #1276

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant