1

I want to display my database entries. Angular repeats list items but doesn't display any values. The entries database has a title column.

View:

<div ng-controller="EntryCtrl">
  <h2>Angular Display</h2>
  <ul>
    <li ng-repeat="entry in entries">
        {{entry.title}}
    </li>
  </ul>
</div>

Coffee-script:

app = angular.module("Resume", ["ngResource"])

app.factory "Entry", ["$resource", ($resource) ->
  $resource("/entries/:id", {id: "@id"}, {update: {method: "GET"}})
]

@EntryCtrl = ["$scope", "Entry", ($scope, Entry) ->
  $scope.entries = Entry.get()
]

2 Answers 2

4

$resource.get is used for fetching single object instance:

$scope.entry = Entry.get({id:123}, callback);

and $resource.query is used for retrieving a collection:

$scope.entries = Entry.query();
Sign up to request clarification or add additional context in comments.

1 Comment

The get/query issue was a bi-product of troubleshooting. Thanks for the clarification though.
2

To fix, I had to add:

    respond_to :json, :html

and:

    respond_with Entry.all

...to the controller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.