0

I am trying to display a list of my donors - the html is:

<div class="panel">
<header>
 <h1> Donor Information </h1>
</header>

<div class="content">
 <div ng-app="Donor">
  <div ng-controller="DonorCtrl">

  <ul>
   <li ng-repeat="donor in donors">{{donors.name_last | json}}</li>
  </ul>

   </div>
  </div>
 </div>
</div>

My Donor_controller.js is this:

var app;
app = angular.module("Donor", ["ngResource"]);

app.factory("Donors", [
   "$resource", function($resource) {
    return $resource("/donors", {}, {
        update: {
            method: "PUT"
        }
    });
  }
]);

app.factory("Donor", [
"$resource", function($resource) {
    return $resource("/donors/:id", {
        id: "@id"
    }, {
        update: {
            method: "GET"
        }
    });
  }
]);

this.DonorCtrl = [
 "$scope", "Donor", "Donors", function($scope, Donor, Donors) {
    var donor;
    $scope.donor = Donor.query();
    $scope.donors = Donors;
    $scope.addDonor = function() {};
    donor = Donor.save($scope.newDonor)(function() {
        return $scope.donors.push(donor);
    });
    return $scope.newDonor = {};
  }
];

I am returning from my rails app via donors/1.json this:

{
  "donor": {
  "id": 1,
  "tools_id": null,
  "first_name": "Billy",
  "last_name": "Bullard"
  }
}

I get a list of dots when I view and it shows this on inspection (repeated):

<li ng-repeat="donor in donors" class="ng-scope ng-binding"></li>

How do I go from the json coming from Rails to the list of names in Angularjs?

4

1 回答 1

2

您应该| json从绑定中删除,并且您想要donor' 姓氏,而不是donors':

<li ng-repeat="donor in donors">{{donor.name_last}}</li>

更新 1

此外,你应该$scope.donors = Donors.query();在你的控制器中,而不是$scope.donor = ....

于 2013-03-30T13:37:47.527 回答