mercredi 23 décembre 2015

index.html being loaded as one of my data models

I am using Ember-CLI with Ember 2.2.0 and Ember Data 2.0. This problem was happening before I upgraded my ember-cli to the latest ember.

I have a fairly simple Ember app. There is a 'users' file on my server hard coded for testing with some json of some sample user accounts. http://ift.tt/1qP7lOb

{"users": [{"id":1,"firstName":"Peter","lastName":"blah","email":"blah@example.com","password":"blah","phone":"212-555-1212","isActive":"true"},{"id":2,"firstName":"George","lastName":"blah","email":"blah2@example.com","password":"blah","phone":"310-555-1212","isActive":"true"}]}

On my development machine I have a generated Ember-cli app with the following modifications:

router.js
...
Router.map(function() {
  this.route('users', function() {});
});

...

users.hbs
<h1>Users Route</h1>

<h1>Users Index</h1>
<Table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone</th>
</tr>

{{#each users as |user|}}
<tr>
<td>{{user.firstName}}</td>
<td>{{user.lastName}}</td>
<td>{{user.email}}</td>
<td>{{user.phone}}</td>
</tr>
{{/each}}

</table>
{{outlet}}

in my routes folder:

user.js
export default Ember.Route.extend({
    model: function() {
        return this.store.findAll('user');
    }
});

Ember throws the following parsing error when it tries to access the users model:

Error while processing route: users.index Unexpected token < SyntaxError: Unexpected token <

I can clearly see in the ember inspector that it is trying to parse my index.html page!! WTH??

index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>UserMan</title>
....

Even if I go to the ember inspector, and go to the users route, then try and access the model using the store:

$E.store.findAll('user')

The parsing error happens and its clearly trying to parse the index.html page again.

Any ideas where ember is going wrong? Or what I am doing wrong?




Aucun commentaire:

Enregistrer un commentaire