Sander,

How are you able to post code into the response?

ng-repeat is in there I just didnt show it in my example.  Here is my 
entire view:

<div ng-controller="TodoController">
  <h2 class="index_header">Total todos: {{getTotalTodos()}}</h2>
  <ul>
    <li ng-repeat="todo in todos | orderBy:'-importance'">
      <input type="checkbox" ng-model="todo.done">
      <span class="done-{{todo.done}} todos">{{todo.title}} - 
{{todo.importance}}</span>
    </li>
  </ul>
  <form class="form-inline">
    <input type="text" ng-model="newTodo.title" placeholder="item" 
class="placeholder">
    <input type="text" ng-model='newTodo.description' 
placeholder="description" class="placeholder">
    <input type="number" ng-model="newTodo.importance" 
placeholder="importance" class="placeholder">
    <button class="styled-button-2" ng-click="addTodo()">Add 
Item</button><br>
    <span class="binding">{{newTodo.title}}</span><br>
    {{newTodo.description}}<br>
    {{newTodo.importance}}
  </form>
  <button class="styled-button-5" ng-click="clearCompleted()">Clear 
Completed Items</button>
</div>

And then here is the corresponding js file:

angular.module("Todo", ["ngResource"])

function TodoController($scope, $filter, $resource) {
  Todo = $resource("/todos", {id: "@id"}, {update: {method: 'PUT'}})
  $scope.todos = Todo.query()

  $scope.getTotalTodos = function () {
    return $scope.todos.length;
  };

  $scope.clearCompleted = function () {
    Todo.save({done:true})
    $scope.todos = $filter("filter")($scope.todos, {done:false});
};

  $scope.addTodo = function () {
    entry = Todo.save({title:$scope.newTodo.title, 
importance:$scope.newTodo.importance, 
description:$scope.newTodo.description, done:false})
    $scope.todos.push(entry);
    $scope.newTodo.title = '';
    $scope.newTodo.importance = '';
    $scope.newTodo.description = '';
  };

}

To recap, what is happening is the object is able to be created and saved 
to the database to that after I create it, it not only goes into the list 
in the view the way I want it to, but it also shows up in the rails console 
as the latest object.

The issue is still when I refresh the page.  I expect to see a list of all 
the created objects and I do not.  The list comes in with 0 objects.

In the terminal I see:

Processing by TodosController#index as HTML
  Todo Load (13.0ms)  SELECT "todos".* FROM "todos" 

The index action in the TodosController looks like this:

  def index
    respond_with Todo.all
  end

and when I run SELECT "todos".* FROM "todos" in the console I actually see 
multiple objects, so I am guessing the issue is still with associating the 
array of objects from my angular controller.

On Saturday, January 4, 2014 12:37:47 AM UTC-5, Sander Elias wrote:
>
> Hi Steven,
>
> you seem to have missed an ng-repeat in your sample, this might get you 
> going:
>
> <div class="roundedTwo" ng-repeat='todo in todos'>
>         <input type="checkbox" ng-model="todo.done">
>         <span class="done-{{todo.done}} todos">{{todo.title}} - 
> {{todo.importance}}</span>
> </div>
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to