我正在尝试使用 ngResource 在 angularjs 中重新创建以下 erb 模板,但似乎无法弄清楚如何访问 event.spikes(这是一个 has_many 关系)。
我要更改的erb文件:
<div class='event-list'>
<ul>
<% @events.each do |event| %>
<li><%= event.name %> || <small><%= event.date %></small>
<ul>
<% event.spikes.each do |spike| %>
<li>Time of Spike: <%= spike.date_time %> || Spike Velocity: <%= spike.peak_velocity %></li>
<% end %>
</ul>
</li>
<% end %>
</ul>
</div>
没有erb的半成品.html:
<div class='event-list' ng-controller='EventsCtrl'>
<ul>
<li ng-repeat='event in events'>
{{ event.name }} || <small>{{ event.date }}</small>
<ul>
<<<<<SOMETHING GOES HERE???>>>>>>>>
</ul>
</li>
</ul>
</div>
这是我的服务,app/assets/javascripts/angular/controllers/event.js:
App.factory('Event', ['$resource', function($resource) {
return $resource('/events/:id', { id: '@id' });
}]);
我的角度控制器,app/assets/javascripts/angular/controllers/events.ctrl.js:
App.controller('EventsCtrl', ['$scope', 'Event', function($scope, Event) {
$scope.events = Event.query();
}]);
在我的角度应用程序定义的地方,app/assets/javascripts/app.js:
window.App = angular.module('sportsSpike', ['ngResource']);