aurelia / http-client

A simple, restful, message-based wrapper around XMLHttpRequest.
MIT License
62 stars 59 forks source link

"repeat.for" construct fails as a function of http-client data source #72

Closed adriatic closed 9 years ago

adriatic commented 9 years ago

This is weird and I hope is not a silly pilot error. I have a simple pair {app.js, app.html} defined as

import {HttpClient} from "aurelia-http-client";

export class App {

    constructor () {
        this.http = new HttpClient();
    }

    activate() {
        return this.http.get("/api/movies")
                        .then (response => {
                            this.movies = response.content;
                        });
    }

}

and

<template>

    <div class="container">

        <div> You have ${movies.length} movies.</div>

        <table class="table">
            <tr>
                <th>Title</th>
                <th>Year</th>
            </tr>
            <tr repeat.for="movie of movies">
                <td>${movie.title}</td>
                <td>${movie.releaseYear}</td>
            </tr>
        </table>
    </div>

</template>

here is the screenshot of the Chrome debugger in action

image

which indicates that the http.get() method fetched the correct content. The app.html renders the view shown below:

image

Note that ${movies.length} correctly evaluates to 3 - while the loop repeat.for="movie of movies" gets executed 0 times.

What is really weird is that replacing the http.get("/api/movies") with http.get("/movies.json") which is the reference to the file in the client's root folder as shown below

image

without any other changes in this project results with what one would expect:

image

bryanrsmith commented 9 years ago

The casing of the property names is different in your chrome debugger screenshot. I'm guessing your server is using different json serialization settings than what's in the file. Try movie.Title and movie.ReleaseYear in your bindings.

adriatic commented 9 years ago

Thanks Bryan for showing me that I am blind with healthy eyes (this is probably the case number 1321 in the long series of such proofs). My excuse is always the same: interacting with some new product I would always suspect to see a lot of bugs - and never in my own code / data. So, my assumption that the repeat.for did not execute, was false - there was nothing to show in each pass of the loop :-(

I also find interesting that you live in Bellingham, my favorite place on the whole world. I used to live in Fairhaven from 2005 until 2013 when I moved to Ann Arbor, MI to be close to my daughter, who works here.

bryanrsmith commented 9 years ago

No worries! Glad it was easily resolved.

Great to hear from another hamster :-) Fairhaven is a wonderful place to live. As it happens, I'm on my way to Mambo for dinner just now. Look me up if you're ever in town for a visit & want to grab a pint.

Cheers, Bryan