2

I am following Ember's TodoMVC tutorial and I am stuck. Basically, I defined 2 controllers. This is todos.js

import Ember from "ember";

export default Ember.ArrayController.extend({
    actions:{
        createTodo: function(){
            var title = this.get("newTitle");

            if(!title){
                return false;
            }
            if(!title.trim()){
                return;
            }

            var todo = this.store.createRecord("todo", {
                title: title,
                isCompleted: false
            });

            // Clear text field
            this.set('newTitle', '');

            todo.save();
        }
    }
})

This is todo.js

import Ember from "ember"

export default Ember.ObjectController.extend({
    isCompleted: function(key, value){
        var model = this.get("model");

        if(value === undefined){
            return model.get("isCompleted");
        } else {
            model.set('isCompleted', value);
            model.save();
            return value;
        }
    }.property('model','model.isCompleted')
});

Here is routes/todos.js

import Ember from "ember";

export default Ember.Route.extend({
    model: function() {
        return this.store.find("todo");
    }
});

Finally, also defined todos.hbs

<ul id="todo-list">
    {{#each todo in model itemController="todo"}}
        <li {{bind-attr class="todo.isCompleted:completed"}}>
            {{input 
            type="checkbox"
            class="toggle"
            checked=todo.isCompleted
            }}
            <label>{{todo.title}}</label><button class="destroy"></button>
        </li>
    {{/each}}
</ul>

Everything looks good, but I am getting the following error in the console:

Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed todomvc-embercli@controller:array:, but it should have been an ArrayController

What am I doing wrong here?

PrestaShopDeveloper
  • 3,110
  • 3
  • 21
  • 30
rreyes1979
  • 1,855
  • 3
  • 23
  • 34
  • Can you post your `todos` route as well? – GJK May 24 '15 at 15:32
  • todos.js route posted :) – rreyes1979 May 24 '15 at 15:35
  • I don't see anything obviously wrong. Do you by chance have [prototype extensions disabled](http://guides.emberjs.com/v1.11.0/configuring-ember/disabling-prototype-extensions/)? – GJK May 24 '15 at 15:36
  • I just added the following: EmberENV: { FEATURES: { EXTEND_PROTOTYPES: true } } into config/environment.js. Same result. Here is the complete environment.js file: https://code.stypi.com/w2v2pkm5 – rreyes1979 May 24 '15 at 15:43
  • Out of curiosity, can you trying changing your controller so it extends from just `Controller` instead of `ArrayController`? Also, would you mind posting the version of Ember you're using as well? – GJK May 24 '15 at 15:53
  • Extended from Controller. Same thing. About library versions, this is what I see in the console: Ember: 1.9.1, Ember Data : 1.0.0-beta.17, Handlebars : 2.0.0, jQuery : 1.11.3 – rreyes1979 May 24 '15 at 16:28
  • I'll be honest, I'm a little lost at this point. :/ It seems like an Ember quirk/bug, but not one that I've seen before. Can you try removing the `itemController` from your loop? – GJK May 24 '15 at 17:13
  • If removed, it works again :) – rreyes1979 May 24 '15 at 17:46
  • There's definitely something fishy with Ember then. I remember a certain scenario where item controllers don't work. I'll try to dig it and up and get back to you with a fix. – GJK May 24 '15 at 18:32

2 Answers2

1

As per turboMaCk's comment, removing ember-disable-proxy-controllers from package.json seems to fix the issue.

Flobin
  • 626
  • 1
  • 10
  • 26
0

This issue was just reported yesterday on the Ember GitHub page. It seems to be a bug with Ember and I don't know of a workaround. However, it does mention that you can use components instead of a array and item controllers (which is the preferred method anyway). Maybe try looking at this gist that was posted in the issue.

I'll come back and update this answer if a workaround/fix is found. For now, I would say try to avoid array controllers (even though it's in the tutorial). :/

GJK
  • 37,023
  • 8
  • 55
  • 74