2
votes

I'm having problems with iron-ajax and data binding in Polymer 1.0.2. Not even a slightly changed example from the Polymer documentation is working.

Here is the code with my changes:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script src="../../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
    <link rel="import" href="../../../bower_components/polymer/polymer.html">
    <link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html">

</head>
<body>

<template is="dom-bind">

    <iron-ajax
            auto
            url="http://jsonplaceholder.typicode.com/posts/"
            lastResponse="{{data}}"
            handleAs="json">
    </iron-ajax>

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

</template>

<script>
    (function (document) {
        'use strict';

        var app = document.querySelector('#app');

        window.addEventListener('WebComponentsReady', function() {
            var ironAjax = document.querySelector('iron-ajax');
            ironAjax.addEventListener('response', function() {
                console.log(ironAjax.lastResponse[0].id);
            });
            ironAjax.generateRequest();
        });

    })(document);

</script>
</body>
</html>

All I changed was entering a URL to get a real JSON response and setting the auto and handleAs properties. I also added a small script with a listener for the response event. The listener is working fine and handles the response, but the spans in the dom-repeat template aren't rendered.

I'm using Polymer 1.0.2 and iron-elements 1.0.0

2
I had a similar issue, look here for my question and the two answers (including my own!) and see if they help. - Ben Thomas

2 Answers

10
votes

It seems the documentation you is missing a - character in the lastresponse attribute of the example.

You must change lastResponse to last-response. Look at this example from the iron-ajax github page.

2
votes

when you use a attribute on a element, you have to convert the camelcase sentence to dashes sentence, I mean:

lastResponse is maps to last-response

Property name to attribute name mapping